missing function reference
[oweals/gnunet.git] / src / include / gnunet_transport_service.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
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 2, or (at your
8      option) any later version.
9
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.
14
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.
19 */
20
21 /**
22  * @file include/gnunet_transport_service.h
23  * @brief low-level P2P IO
24  * @author Christian Grothoff
25  *
26  * TODO:
27  * - define API for blacklisting, un-blacklisting and notifications
28  *   about blacklisted peers
29  */
30
31 #ifndef GNUNET_TRANSPORT_SERVICE_H
32 #define GNUNET_TRANSPORT_SERVICE_H
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42 #include "gnunet_configuration_lib.h"
43 #include "gnunet_crypto_lib.h"
44 #include "gnunet_connection_lib.h"
45 #include "gnunet_scheduler_lib.h"
46 #include "gnunet_time_lib.h"
47
48 /**
49  * Version number of the transport API.
50  */
51 #define GNUNET_TRANSPORT_VERSION 0x00000000
52
53 /**
54  * Function called by the transport for each received message.
55  *
56  * @param cls closure
57  * @param peer (claimed) identity of the other peer
58  * @param message the message
59  * @param latency estimated latency for communicating with the
60  *             given peer (round-trip)
61  * @param distance in overlay hops, as given by transport plugin
62  */
63 typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
64                                                   const struct
65                                                   GNUNET_PeerIdentity * peer,
66                                                   const struct
67                                                   GNUNET_MessageHeader *
68                                                   message,
69                                                   struct GNUNET_TIME_Relative
70                                                   latency,
71                                                   uint32_t distance);
72
73
74 /**
75  * Opaque handle to the service.
76  */
77 struct GNUNET_TRANSPORT_Handle;
78
79
80 /**
81  * Function called to notify transport users that another
82  * peer connected to us.
83  *
84  * @param cls closure
85  * @param peer the peer that connected
86  * @param latency estimated latency for communicating with the
87  *             given peer (round-trip)
88  * @param distance in overlay hops, as given by transport plugin
89  */
90 typedef void
91   (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
92                                      const struct GNUNET_PeerIdentity * peer,
93                                      struct GNUNET_TIME_Relative latency,
94                                      uint32_t distance);
95
96 /**
97  * Function called to notify transport users that another
98  * peer disconnected from us.
99  *
100  * @param cls closure
101  * @param peer the peer that disconnected
102  */
103 typedef void
104   (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
105                                         const struct GNUNET_PeerIdentity *
106                                         peer);
107
108
109 /**
110  * Function to call with a human-readable format of an address
111  *
112  * @param cls closure
113  * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
114  */
115 typedef void
116 (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
117                                            const char *address);
118
119
120 /**
121  * Connect to the transport service.  Note that the connection may
122  * complete (or fail) asynchronously.
123  *
124  * @param sched scheduler to use
125  * @param cfg configuration to use
126  * @param cls closure for the callbacks
127  * @param rec receive function to call
128  * @param nc function to call on connect events
129  * @param nd function to call on disconnect events
130  * @return NULL on error
131  */
132 struct GNUNET_TRANSPORT_Handle *GNUNET_TRANSPORT_connect (struct
133                                                           GNUNET_SCHEDULER_Handle
134                                                           *sched,
135                                                           const struct
136                                                           GNUNET_CONFIGURATION_Handle
137                                                           *cfg, void *cls,
138                                                           GNUNET_TRANSPORT_ReceiveCallback
139                                                           rec,
140                                                           GNUNET_TRANSPORT_NotifyConnect
141                                                           nc,
142                                                           GNUNET_TRANSPORT_NotifyDisconnect
143                                                           nd);
144
145
146 /**
147  * Disconnect from the transport service.
148  *
149  * @param handle handle returned from connect
150  */
151 void GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
152
153
154 /**
155  * Set the share of incoming/outgoing bandwidth for the given
156  * peer to the specified amount.
157  *
158  * @param handle connection to transport service
159  * @param target who's bandwidth quota is being changed
160  * @param quota_in incoming bandwidth quota in bytes per ms
161  * @param quota_out outgoing bandwidth quota in bytes per ms
162  * @param timeout how long to wait until signaling failure if
163  *        we can not communicate the quota change
164  * @param cont continuation to call when done, will be called
165  *        either with reason "TIMEOUT" or with reason "PREREQ_DONE"
166  * @param cont_cls closure for continuation
167  */
168 void
169 GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
170                             const struct GNUNET_PeerIdentity *target,
171                             uint32_t quota_in,
172                             uint32_t quota_out,
173                             struct GNUNET_TIME_Relative timeout,
174                             GNUNET_SCHEDULER_Task cont, void *cont_cls);
175
176
177 /**
178  * Opaque handle for a transmission-ready request.
179  */
180 struct GNUNET_TRANSPORT_TransmitHandle;
181
182
183 /**
184  * Check if we could queue a message of the given size for
185  * transmission.  The transport service will take both its
186  * internal buffers and bandwidth limits imposed by the
187  * other peer into consideration when answering this query.
188  *
189  * @param handle connection to transport service
190  * @param target who should receive the message
191  * @param size how big is the message we want to transmit?
192  * @param priority how important is the message?
193  * @param timeout after how long should we give up (and call
194  *        notify with buf NULL and size 0)?
195  * @param notify function to call when we are ready to
196  *        send such a message
197  * @param notify_cls closure for notify
198  * @return NULL if someone else is already waiting to be notified
199  *         non-NULL if the notify callback was queued (can be used to cancel
200  *         using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
201  */
202 struct GNUNET_TRANSPORT_TransmitHandle
203   *GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
204                                            *handle,
205                                            const struct GNUNET_PeerIdentity
206                                            *target, size_t size,
207                                            uint32_t priority,
208                                            struct GNUNET_TIME_Relative
209                                            timeout,
210                                            GNUNET_CONNECTION_TransmitReadyNotify
211                                            notify, void *notify_cls);
212
213
214 /**
215  * Cancel the specified transmission-ready notification.
216  *
217  * @param h handle of the transmission notification request to cancel
218  */
219 void
220 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
221                                                GNUNET_TRANSPORT_TransmitHandle
222                                                *h);
223
224
225
226 /**
227  * Function called whenever there is an update to the
228  * HELLO of this peer.
229  *
230  * @param cls closure
231  * @param hello our updated HELLO
232  */
233 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback)(void *cls,
234                                                      const struct GNUNET_MessageHeader *hello);
235
236
237 /**
238  * Obtain updates on changes to the HELLO message for this peer.
239  *
240  * @param handle connection to transport service
241  * @param rec function to call with the HELLO
242  * @param rec_cls closure for rec
243  */
244 void
245 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
246                             GNUNET_TRANSPORT_HelloUpdateCallback rec,
247                             void *rec_cls);
248
249
250 /**
251  * Stop receiving updates about changes to our HELLO message.
252  *
253  * @param handle connection to transport service
254  * @param rec function previously registered to be called with the HELLOs
255  * @param rec_cls closure for rec
256  */
257 void
258 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
259                                    GNUNET_TRANSPORT_HelloUpdateCallback rec,
260                                    void *rec_cls);
261
262
263 /**
264  * Offer the transport service the HELLO of another peer.  Note that
265  * the transport service may just ignore this message if the HELLO is
266  * malformed or useless due to our local configuration.  If the HELLO
267  * is working, we should add it to PEERINFO.
268  *
269  * @param handle connection to transport service
270  * @param hello the hello message
271  */
272 void
273 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
274                               const struct GNUNET_MessageHeader *hello);
275
276
277 /**
278  * Convert a binary address into a human readable address.
279  *
280  * @param sched scheduler to use
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  */
291 void
292 GNUNET_TRANSPORT_address_lookup (struct GNUNET_SCHEDULER_Handle *sched,
293                                  const struct GNUNET_CONFIGURATION_Handle *cfg,
294                                  const char * address,
295                                  size_t addressLen,
296                                  int numeric,
297                                  const char * nameTrans,
298                                  struct GNUNET_TIME_Relative timeout,
299                                  GNUNET_TRANSPORT_AddressLookUpCallback aluc,
300                                  void *aluc_cls);
301
302
303
304 /**
305  * Handle for blacklisting requests.
306  */
307 struct GNUNET_TRANSPORT_BlacklistRequest;
308
309
310 /**
311  * Blacklist a peer for a given period of time.  All connections
312  * (inbound and outbound) to a peer that is blacklisted will be
313  * dropped (as soon as we learn who the connection is for).  A second
314  * call to this function for the same peer overrides previous
315  * blacklisting requests.
316  *
317  * @param sched scheduler to use
318  * @param cfg configuration to use
319  * @param peer identity of peer to blacklist
320  * @param duration how long to blacklist, use GNUNET_TIME_UNIT_ZERO to
321  *        re-enable connections
322  * @param timeout when should this operation (trying to establish the
323  *        blacklisting time out)
324  * @param cont continuation to call once the request has been processed
325  * @param cont_cls closure for cont
326  * @return NULL on error, otherwise handle for cancellation
327  */
328 struct GNUNET_TRANSPORT_BlacklistRequest *
329 GNUNET_TRANSPORT_blacklist (struct GNUNET_SCHEDULER_Handle *sched,
330                             const struct GNUNET_CONFIGURATION_Handle *cfg,
331                             const struct GNUNET_PeerIdentity *peer,
332                             struct GNUNET_TIME_Relative duration,
333                             struct GNUNET_TIME_Relative timeout,
334                             GNUNET_SCHEDULER_Task cont,
335                             void *cont_cls);
336
337
338 /**
339  * Abort transmitting the blacklist request.  Note that this function
340  * is NOT for removing a peer from the blacklist (for that, call 
341  * GNUNET_TRANSPORT_blacklist with a duration of zero).  This function
342  * is only for aborting the transmission of a blacklist request
343  * (i.e. because of shutdown).
344  *
345  * @param br handle of the request that is to be cancelled
346  */
347 void
348 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_BlacklistRequest * br);
349
350
351 /**
352  * Handle for blacklist notifications.
353  */
354 struct GNUNET_TRANSPORT_BlacklistNotification;
355
356
357 /**
358  * Signature of function called whenever the blacklist status of
359  * a peer changes.  This includes changes to the duration of the
360  * blacklist status as well as the expiration of an existing
361  * blacklist status.
362  *
363  * @param cls closure
364  * @param peer identity of peer with the change
365  * @param until GNUNET_TIME_UNIT_ZERO_ABS if the peer is no
366  *              longer blacklisted, otherwise the time at
367  *              which the current blacklisting will expire
368  */
369 typedef void (*GNUNET_TRANSPORT_BlacklistCallback)(void *cls,
370                                                    const struct GNUNET_PeerIdentity *peer,
371                                                    struct GNUNET_TIME_Absolute until);
372
373
374 /**
375  * Call a function whenever a peer's blacklisting status changes.
376  *
377  * @param sched scheduler to use
378  * @param cfg configuration to use
379  * @param bc function to call on status changes
380  * @param bc_cls closure for bc
381  * @return NULL on error, otherwise handle for cancellation
382  */
383 struct GNUNET_TRANSPORT_BlacklistNotification *
384 GNUNET_TRANSPORT_blacklist_notify (struct GNUNET_SCHEDULER_Handle *sched,
385                                    const struct GNUNET_CONFIGURATION_Handle *cfg,
386                                    GNUNET_TRANSPORT_BlacklistCallback bc,
387                                    void *bc_cls);
388
389
390 /**
391  * Stop calling the notification callback associated with
392  * the given blacklist notification.
393  *
394  * @param bn handle of the request that is to be cancelled
395  */
396 void
397 GNUNET_TRANSPORT_blacklist_notify_cancel (struct GNUNET_TRANSPORT_BlacklistNotification * bn);
398
399
400
401 #if 0                           /* keep Emacsens' auto-indent happy */
402 {
403 #endif
404 #ifdef __cplusplus
405 }
406 #endif
407
408 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
409 #endif
410 /* end of gnunet_transport_service.h */