2 This file is part of GNUnet.
3 (C) 2009 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_bandwidth_lib.h"
39 #include "gnunet_configuration_lib.h"
40 #include "gnunet_crypto_lib.h"
41 #include "gnunet_connection_lib.h"
42 #include "gnunet_scheduler_lib.h"
43 #include "gnunet_time_lib.h"
46 * Version number of the transport API.
48 #define GNUNET_TRANSPORT_VERSION 0x00000000
51 * Function called by the transport for each received message.
54 * @param peer (claimed) identity of the other peer
55 * @param message the message
56 * @param latency estimated latency for communicating with the
57 * given peer (round-trip)
58 * @param distance in overlay hops, as given by transport plugin
60 typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
62 GNUNET_PeerIdentity * peer,
64 GNUNET_MessageHeader *
66 struct GNUNET_TIME_Relative
72 * Opaque handle to the service.
74 struct GNUNET_TRANSPORT_Handle;
78 * Function called to notify transport users that another
79 * peer connected to us.
82 * @param peer the peer that connected
83 * @param latency estimated latency for communicating with the
84 * given peer (round-trip)
85 * @param distance in overlay hops, as given by transport plugin
88 (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
89 const struct GNUNET_PeerIdentity * peer,
90 struct GNUNET_TIME_Relative latency,
94 * Function called to notify transport users that another
95 * peer disconnected from us.
98 * @param peer the peer that disconnected
101 (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
102 const struct GNUNET_PeerIdentity *
107 * Function to call with a human-readable format of an address
110 * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
113 (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
114 const char *address);
118 * Connect to the transport service. Note that the connection may
119 * complete (or fail) asynchronously.
121 * @param sched scheduler to use
122 * @param cfg configuration to use
123 * @param self our own identity (API should check that it matches
124 * the identity found by transport), or NULL (no check)
125 * @param cls closure for the callbacks
126 * @param rec receive function to call
127 * @param nc function to call on connect events
128 * @param nd function to call on disconnect events
129 * @return NULL on error
131 struct GNUNET_TRANSPORT_Handle *GNUNET_TRANSPORT_connect (struct
132 GNUNET_SCHEDULER_Handle
135 GNUNET_CONFIGURATION_Handle
137 const struct GNUNET_PeerIdentity *self,
139 GNUNET_TRANSPORT_ReceiveCallback
141 GNUNET_TRANSPORT_NotifyConnect
143 GNUNET_TRANSPORT_NotifyDisconnect
148 * Disconnect from the transport service.
150 * @param handle handle returned from connect
152 void GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
156 * Set the share of incoming/outgoing bandwidth for the given
157 * peer to the specified amount.
159 * @param handle connection to transport service
160 * @param target who's bandwidth quota is being changed
161 * @param quota_in incoming bandwidth quota
162 * @param quota_out outgoing bandwidth quota
163 * @param timeout how long to wait until signaling failure if
164 * we can not communicate the quota change
165 * @param cont continuation to call when done, will be called
166 * either with reason "TIMEOUT" or with reason "PREREQ_DONE"
167 * @param cont_cls closure for continuation
170 GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
171 const struct GNUNET_PeerIdentity *target,
172 struct GNUNET_BANDWIDTH_Value32NBO quota_in,
173 struct GNUNET_BANDWIDTH_Value32NBO quota_out,
174 struct GNUNET_TIME_Relative timeout,
175 GNUNET_SCHEDULER_Task cont, void *cont_cls);
179 * Opaque handle for a transmission-ready request.
181 struct GNUNET_TRANSPORT_TransmitHandle;
185 * Check if we could queue a message of the given size for
186 * transmission. The transport service will take both its internal
187 * buffers and bandwidth limits imposed by the other peer into
188 * consideration when answering this query.
190 * @param handle connection to transport service
191 * @param target who should receive the message
192 * @param size how big is the message we want to transmit?
193 * @param priority how important is the message?
194 * @param timeout after how long should we give up (and call
195 * notify with buf NULL and size 0)?
196 * @param notify function to call when we are ready to
197 * send such a message
198 * @param notify_cls closure for notify
199 * @return NULL if someone else is already waiting to be notified
200 * non-NULL if the notify callback was queued (can be used to cancel
201 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
203 struct GNUNET_TRANSPORT_TransmitHandle
204 *GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
206 const struct GNUNET_PeerIdentity
207 *target, size_t size,
209 struct GNUNET_TIME_Relative
211 GNUNET_CONNECTION_TransmitReadyNotify
212 notify, void *notify_cls);
216 * Cancel the specified transmission-ready notification.
218 * @param h handle of the transmission notification request to cancel
221 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
222 GNUNET_TRANSPORT_TransmitHandle
228 * Function called whenever there is an update to the
229 * HELLO of this peer.
232 * @param hello our updated HELLO
234 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback)(void *cls,
235 const struct GNUNET_MessageHeader *hello);
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
246 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
247 GNUNET_TRANSPORT_HelloUpdateCallback rec,
252 * Stop receiving updates about changes to our HELLO message.
254 * @param handle connection to transport service
255 * @param rec function previously registered to be called with the HELLOs
256 * @param rec_cls closure for rec
259 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
260 GNUNET_TRANSPORT_HelloUpdateCallback rec,
265 * Offer the transport service the HELLO of another peer. Note that
266 * the transport service may just ignore this message if the HELLO is
267 * malformed or useless due to our local configuration. If the HELLO
268 * is working, we should add it to PEERINFO.
270 * @param handle connection to transport service
271 * @param hello the hello message
274 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
275 const struct GNUNET_MessageHeader *hello);
279 * Convert a binary address into a human readable address.
281 * @param sched scheduler to use
282 * @param cfg configuration to use
283 * @param address address to convert (binary format)
284 * @param addressLen number of bytes in address
285 * @param numeric should (IP) addresses be displayed in numeric form
286 * (otherwise do reverse DNS lookup)
287 * @param nameTrans name of the transport to which the address belongs
288 * @param timeout how long is the lookup allowed to take at most
289 * @param aluc function to call with the results
290 * @param aluc_cls closure for aluc
293 GNUNET_TRANSPORT_address_lookup (struct GNUNET_SCHEDULER_Handle *sched,
294 const struct GNUNET_CONFIGURATION_Handle *cfg,
295 const char * address,
298 const char * nameTrans,
299 struct GNUNET_TIME_Relative timeout,
300 GNUNET_TRANSPORT_AddressLookUpCallback aluc,
306 * Handle for blacklisting peers.
308 struct GNUNET_TRANSPORT_Blacklist;
312 * Function that decides if a connection is acceptable or not.
315 * @param pid peer to approve or disapproave
316 * @return GNUNET_OK if the connection is allowed
318 typedef int (*GNUNET_TRANSPORT_BlacklistCallback)(void *cls,
319 const struct GNUNET_PeerIdentity *pid);
323 * Install a blacklist callback. The service will be queried for all
324 * existing connections as well as any fresh connections to check if
325 * they are permitted. If the blacklisting callback is unregistered,
326 * all hosts that were denied in the past will automatically be
327 * whitelisted again. Cancelling the blacklist handle is also the
328 * only way to re-enable connections from peers that were previously
331 * @param sched scheduler to use
332 * @param cfg configuration to use
333 * @param cb callback to invoke to check if connections are allowed
334 * @param cb_cls closure for cb
335 * @return NULL on error, otherwise handle for cancellation
337 struct GNUNET_TRANSPORT_Blacklist *
338 GNUNET_TRANSPORT_blacklist (struct GNUNET_SCHEDULER_Handle *sched,
339 const struct GNUNET_CONFIGURATION_Handle *cfg,
340 GNUNET_TRANSPORT_BlacklistCallback cb,
345 * Abort the blacklist. Note that this function is the only way for
346 * removing a peer from the blacklist.
348 * @param br handle of the request that is to be cancelled
351 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
355 #if 0 /* keep Emacsens' auto-indent happy */
362 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
364 /* end of gnunet_transport_service.h */