-doxygen, plus FIXME request for clarification
[oweals/gnunet.git] / src / include / gnunet_transport_service.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009-2014 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 3, 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
27 #ifndef GNUNET_TRANSPORT_SERVICE_H
28 #define GNUNET_TRANSPORT_SERVICE_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_util_lib.h"
39 #include "gnunet_ats_service.h"
40
41 /**
42  * Version number of the transport API.
43  */
44 #define GNUNET_TRANSPORT_VERSION 0x00000001
45
46
47 /**
48  * Possible state of a neighbour.  Initially, we are #GNUNET_TRANSPORT_PS_NOT_CONNECTED.
49  *
50  * Then, there are two main paths. If we receive a CONNECT message, we give
51  * the inbound address to ATS. After the check we ask ATS for a suggestion
52  * (#GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS). If ATS makes a suggestion, we
53  * send our CONNECT_ACK and go to #GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK.
54  * If we receive a SESSION_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
55  * (and notify everyone about the new connection). If the operation times out,
56  * we go to #GNUNET_TRANSPORT_PS_DISCONNECT.
57  *
58  * The other case is where we transmit a CONNECT message first.  We
59  * start with #GNUNET_TRANSPORT_PS_INIT_ATS.  If we get an address, we send
60  * the CONNECT message and go to state #GNUNET_TRANSPORT_PS_CONNECT_SENT.
61  * Once we receive a CONNECT_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
62  * (and notify everyone about the new connection and send
63  * back a SESSION_ACK).  If the operation times out, we go to
64  * #GNUNET_TRANSPORT_PS_DISCONNECT.
65  *
66  * If the session is in trouble (i.e. transport-level disconnect or
67  * timeout), we go to #GNUNET_TRANSPORT_PS_RECONNECT_ATS where we ask ATS for a new
68  * address (we don't notify anyone about the disconnect yet).  Once we
69  * have a new address, we enter #GNUNET_TRANSPORT_PS_RECONNECT_SENT and send a
70  * CONNECT message.  If we receive a
71  * CONNECT_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED and nobody noticed that we had
72  * trouble; we also send a SESSION_ACK at this time just in case.  If
73  * the operation times out, we go to #GNUNET_TRANSPORT_PS_DISCONNECT (and notify everyone
74  * about the lost connection).
75  *
76  * If ATS decides to switch addresses while we have a normal
77  * connection, we go to #GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT
78  * and send a SESSION_CONNECT.  If we get a SESSION_ACK back, we switch the
79  * primary connection to the suggested alternative from ATS, go back
80  * to #GNUNET_TRANSPORT_PS_CONNECTED and send a SESSION_ACK to the other peer just to be
81  * sure.  If the operation times out
82  * we go to #GNUNET_TRANSPORT_PS_CONNECTED (and notify ATS that the given alternative
83  * address is "invalid").
84  *
85  * Once a session is in #GNUNET_TRANSPORT_PS_DISCONNECT, it is cleaned up and then goes
86  * to (#GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED).  If we receive an explicit disconnect
87  * request, we can go from any state to #GNUNET_TRANSPORT_PS_DISCONNECT, possibly after
88  * generating disconnect notifications.
89  *
90  * Note that it is quite possible that while we are in any of these
91  * states, we could receive a 'CONNECT' request from the other peer.
92  * We then enter a 'weird' state where we pursue our own primary state
93  * machine (as described above), but with the 'send_connect_ack' flag
94  * set to 1.  If our state machine allows us to send a 'CONNECT_ACK'
95  * (because we have an acceptable address), we send the 'CONNECT_ACK'
96  * and set the 'send_connect_ack' to 2.  If we then receive a
97  * 'SESSION_ACK', we go to #GNUNET_TRANSPORT_PS_CONNECTED (and reset 'send_connect_ack'
98  * to 0).
99  *
100  */
101 enum GNUNET_TRANSPORT_PeerState
102 {
103   /**
104    * Fresh peer or completely disconnected
105    */
106   GNUNET_TRANSPORT_PS_NOT_CONNECTED = 0,
107
108   /**
109    * Asked to initiate connection, trying to get address from ATS
110    */
111   GNUNET_TRANSPORT_PS_INIT_ATS,
112
113   /**
114    * Sent CONNECT message to other peer, waiting for CONNECT_ACK
115    */
116   GNUNET_TRANSPORT_PS_CONNECT_SENT,
117
118   /**
119    * Received a CONNECT, asking ATS about address suggestions.
120    */
121   GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS,
122
123   /**
124    * CONNECT request from other peer was CONNECT_ACK'ed, waiting for
125    * SESSION_ACK.
126    */
127   GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK,
128
129   /**
130    * Got our CONNECT_ACK/SESSION_ACK, connection is up.
131    */
132   GNUNET_TRANSPORT_PS_CONNECTED,
133
134   /**
135    * Connection got into trouble, rest of the system still believes
136    * it to be up, but we're getting a new address from ATS.
137    */
138   GNUNET_TRANSPORT_PS_RECONNECT_ATS,
139
140   /**
141    * Sent CONNECT over new address (either by ATS telling us to switch
142    * addresses or from RECONNECT_ATS); if this fails, we need to tell
143    * the rest of the system about a disconnect.
144    */
145   GNUNET_TRANSPORT_PS_RECONNECT_SENT,
146
147   /**
148    * We have some primary connection, but ATS suggested we switch
149    * to some alternative; we now sent a CONNECT message for the
150    * alternative session to the other peer and waiting for a
151    * CONNECT_ACK to make this our primary connection.
152    */
153   GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT,
154
155   /**
156    * Disconnect in progress (we're sending the DISCONNECT message to the
157    * other peer; after that is finished, the state will be cleaned up).
158    */
159   GNUNET_TRANSPORT_PS_DISCONNECT,
160
161   /**
162    * We're finished with the disconnect; and are cleaning up the state
163    * now!  We put the struct into this state when we are really in the
164    * task that calls 'free' on it and are about to remove the record
165    * from the map.  We should never find a 'struct NeighbourMapEntry'
166    * in this state in the map.  Accessing a 'struct NeighbourMapEntry'
167    * in this state virtually always means using memory that has been
168    * freed (the exception being the cleanup code in #free_neighbour()).
169    */
170   GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED
171 };
172
173
174 /**
175  * Current state of a validation process.
176  *
177  * FIXME: what state is used to indicate that a validation
178  * was successful? If that is clarified/determined, "UGH" in
179  * ~gnunet-peerinfo-gtk.c:1103 should be resolved.
180  */
181 enum GNUNET_TRANSPORT_ValidationState
182 {
183   /**
184    * Undefined state
185    *
186    * Used for final callback indicating operation done
187    */
188   GNUNET_TRANSPORT_VS_NONE,
189
190   /**
191    * Fresh validation entry
192    *
193    * Entry was just created, no validation process was executed
194    */
195   GNUNET_TRANSPORT_VS_NEW,
196
197   /**
198    * Updated validation entry
199    *
200    * This is an update for an existing validation entry
201    */
202   GNUNET_TRANSPORT_VS_UPDATE,
203
204   /**
205    * Timeout for validation entry
206    *
207    * A timeout occured during the validation process
208    */
209   GNUNET_TRANSPORT_VS_TIMEOUT,
210
211   /**
212    * Validation entry is removed
213    *
214    * The validation entry is getting removed due to a failed validation
215    */
216   GNUNET_TRANSPORT_VS_REMOVE
217 };
218
219
220 /**
221  * Function called by the transport for each received message.
222  *
223  * @param cls closure
224  * @param peer (claimed) identity of the other peer
225  * @param message the message
226  * @param ats performance data
227  * @param ats_count number of entries in @a ats
228  */
229 typedef void
230 (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
231                                      const struct GNUNET_PeerIdentity *peer,
232                                      const struct GNUNET_MessageHeader *message);
233
234
235 /**
236  * Opaque handle to the service.
237  */
238 struct GNUNET_TRANSPORT_Handle;
239
240
241 /**
242  * Function called to notify transport users that another
243  * peer connected to us.
244  *
245  * @param cls closure
246  * @param peer the peer that connected
247  * @param ats performance data
248  * @param ats_count number of entries in @a ats (excluding 0-termination)
249  */
250 typedef void
251 (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
252                                    const struct GNUNET_PeerIdentity *peer);
253
254 /**
255  * Function called to notify transport users that another
256  * peer disconnected from us.
257  *
258  * @param cls closure
259  * @param peer the peer that disconnected
260  */
261 typedef void
262 (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
263                                       const struct GNUNET_PeerIdentity *peer);
264
265
266 /**
267  * Function to call with result of the try connect request.
268  *
269  *
270  * @param cls closure
271  * @param result #GNUNET_OK if message was transmitted to transport service
272  *               #GNUNET_SYSERR if message was not transmitted to transport service
273  */
274 typedef void
275 (*GNUNET_TRANSPORT_TryConnectCallback) (void *cls,
276                                         const int result);
277
278
279 /**
280  * Function to call with a textual representation of an address.
281  * This function will be called several times with different possible
282  * textual representations, and a last time with NULL to signal the end
283  * of the iteration.
284  *
285  * @param cls closure
286  * @param address NULL on error or end of iteration,
287  *        otherwise 0-terminated printable UTF-8 string
288  */
289 typedef void
290 (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
291                                              const char *address);
292
293
294 /**
295  * Function to call with information about a peer
296  *
297  * If one_shot was set to #GNUNET_YES to iterate over all peers once,
298  * a final call with NULL for peer and address will follow when done.
299  * In this case state and timeout do not contain valid values.
300  *
301  * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called from
302  * within this function!
303  *
304  *
305  * @param cls closure
306  * @param peer peer this update is about,
307  *      NULL if this is the final last callback for a iteration operation
308  * @param address address, NULL for disconnect notification in monitor mode
309  * @param state current state this peer is in
310  * @param state_timeout timeout for the current state of the peer
311  */
312 typedef void
313 (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
314                                          const struct GNUNET_PeerIdentity *peer,
315                                          const struct GNUNET_HELLO_Address *address,
316                                          enum GNUNET_TRANSPORT_PeerState state,
317                                          struct GNUNET_TIME_Absolute state_timeout);
318
319
320 /**
321  * Function to call with validation information about a peer
322  *
323  * This function is called by the transport validation monitoring api to
324  * indicate a change to a validation entry. The information included represent
325  * the current state of the validation entry,
326  *
327  * If the monitoring was called with one_shot=GNUNET_YES, a final callback
328  * with peer==NULL and address==NULL is executed.
329  *
330  * @param cls closure
331  * @param peer peer this update is about,
332  *      NULL if this is the final last callback for a iteration operation
333  * @param address address,
334  *      NULL for disconnect notification in monitor mode
335  * @param last_validation when was this address last validated
336  * @param valid_until when does this address expire
337  * @param next_validation time of the next validation operation
338  * @param state state in the validation state machine
339  */
340 typedef void
341 (*GNUNET_TRANSPORT_ValidationIterateCallback) (void *cls,
342                                                const struct GNUNET_PeerIdentity *peer,
343                                                const struct GNUNET_HELLO_Address *address,
344                                                struct GNUNET_TIME_Absolute last_validation,
345                                                struct GNUNET_TIME_Absolute valid_until,
346                                                struct GNUNET_TIME_Absolute next_validation,
347                                                enum GNUNET_TRANSPORT_ValidationState state);
348
349
350 /**
351  * Connect to the transport service.  Note that the connection may
352  * complete (or fail) asynchronously.
353  *
354  * @param cfg configuration to use
355  * @param self our own identity (API should check that it matches
356  *             the identity found by transport), or NULL (no check)
357  * @param cls closure for the callbacks
358  * @param rec receive function to call, or NULL
359  * @param nc function to call on connect events, or NULL
360  * @param nd function to call on disconnect events, or NULL
361  * @return NULL on error
362  */
363 struct GNUNET_TRANSPORT_Handle *
364 GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
365                           const struct GNUNET_PeerIdentity *self,
366                           void *cls,
367                           GNUNET_TRANSPORT_ReceiveCallback rec,
368                           GNUNET_TRANSPORT_NotifyConnect nc,
369                           GNUNET_TRANSPORT_NotifyDisconnect nd);
370
371
372 /**
373  * Function called if we have "excess" bandwidth to a peer.
374  * The notification will happen the first time we have excess
375  * bandwidth, and then only again after the client has performed
376  * some transmission to the peer.
377  *
378  * Excess bandwidth is defined as being allowed (by ATS) to send
379  * more data, and us reaching the limit of the capacity build-up
380  * (which, if we go past it, means we don't use available bandwidth).
381  * See also the "max carry" in `struct GNUNET_BANDWIDTH_Tracker`.
382  *
383  * @param cls the closure
384  * @param peer peer that we have excess bandwidth to
385  */
386 typedef void
387 (*GNUNET_TRANSPORT_NotifyExcessBandwidth)(void *cls,
388                                           const struct GNUNET_PeerIdentity *neighbour);
389
390
391 /**
392  * Connect to the transport service.  Note that the connection may
393  * complete (or fail) asynchronously.
394  *
395  * @param cfg configuration to use
396  * @param self our own identity (API should check that it matches
397  *             the identity found by transport), or NULL (no check)
398  * @param cls closure for the callbacks
399  * @param rec receive function to call, or NULL
400  * @param nc function to call on connect events, or NULL
401  * @param nd function to call on disconnect events, or NULL
402  * @param neb function to call if we have excess bandwidth to a peer
403  * @return NULL on error
404  */
405 struct GNUNET_TRANSPORT_Handle *
406 GNUNET_TRANSPORT_connect2 (const struct GNUNET_CONFIGURATION_Handle *cfg,
407                            const struct GNUNET_PeerIdentity *self,
408                            void *cls,
409                            GNUNET_TRANSPORT_ReceiveCallback rec,
410                            GNUNET_TRANSPORT_NotifyConnect nc,
411                            GNUNET_TRANSPORT_NotifyDisconnect nd,
412                            GNUNET_TRANSPORT_NotifyExcessBandwidth neb);
413
414
415 /**
416  * Disconnect from the transport service.
417  *
418  * @param handle handle returned from connect
419  */
420 void
421 GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
422
423
424 /**
425  * Opaque handle for a transmission-ready request.
426  */
427 struct GNUNET_TRANSPORT_TryConnectHandle;
428
429
430 /**
431  * Ask the transport service to establish a connection to
432  * the given peer.
433  *
434  * @param handle connection to transport service
435  * @param target who we should try to connect to
436  * @param cb callback to be called when request was transmitted to transport
437  *         service
438  * @param cb_cls closure for the callback @a cb
439  * @return a `struct GNUNET_TRANSPORT_TryConnectHandle` handle or
440  *         NULL on failure (@a cb will not be called)
441  */
442 struct GNUNET_TRANSPORT_TryConnectHandle *
443 GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
444                               const struct GNUNET_PeerIdentity *target,
445                               GNUNET_TRANSPORT_TryConnectCallback cb,
446                               void *cb_cls);
447
448
449 /**
450  * Cancel the request to transport to try a connect
451  * Callback will not be called
452  *
453  * @param tch handle to cancel
454  */
455 void
456 GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch);
457
458
459 /**
460  * Ask the transport service to establish a disconnect from
461  * the given peer.
462  *
463  * @param handle connection to transport service
464  * @param target who we should try to disconnect from
465  * @param cb callback to be called when request was transmitted to transport
466  *         service
467  * @param cb_cls closure for the callback @a cb
468  * @return a `struct GNUNET_TRANSPORT_TryConnectHandle` handle or
469  *         NULL on failure (@a cb will not be called)
470  */
471 struct GNUNET_TRANSPORT_TryConnectHandle *
472 GNUNET_TRANSPORT_try_disconnect (struct GNUNET_TRANSPORT_Handle *handle,
473                                  const struct GNUNET_PeerIdentity *target,
474                                  GNUNET_TRANSPORT_TryConnectCallback cb,
475                                  void *cb_cls);
476
477
478 /**
479  * Cancel the request to transport to try a disconnect
480  * Callback will not be called
481  *
482  * @param tch handle for operation to cancel
483  */
484 void
485 GNUNET_TRANSPORT_try_disconnect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch);
486
487
488 /**
489  * Opaque handle for a transmission-ready request.
490  */
491 struct GNUNET_TRANSPORT_TransmitHandle;
492
493
494 /**
495  * Function called to notify a client about the connection begin ready
496  * to queue more data.  @a buf will be NULL and @a size zero if the
497  * connection was closed for writing in the meantime.
498  *
499  * @param cls closure
500  * @param size number of bytes available in @a buf
501  * @param buf where the callee should write the message
502  * @return number of bytes written to @a buf
503  */
504 typedef size_t
505 (*GNUNET_TRANSPORT_TransmitReadyNotify) (void *cls,
506                                          size_t size,
507                                          void *buf);
508
509
510 /**
511  * Check if we could queue a message of the given size for
512  * transmission.  The transport service will take both its internal
513  * buffers and bandwidth limits imposed by the other peer into
514  * consideration when answering this query.
515  *
516  * @param handle connection to transport service
517  * @param target who should receive the message
518  * @param size how big is the message we want to transmit?
519  * @param timeout after how long should we give up (and call
520  *        notify with buf NULL and size 0)?
521  * @param notify function to call when we are ready to
522  *        send such a message
523  * @param notify_cls closure for @a notify
524  * @return NULL if someone else is already waiting to be notified
525  *         non-NULL if the notify callback was queued (can be used to cancel
526  *         using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
527  */
528 struct GNUNET_TRANSPORT_TransmitHandle *
529 GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
530                                         const struct GNUNET_PeerIdentity *target,
531                                         size_t size,
532                                         struct GNUNET_TIME_Relative timeout,
533                                         GNUNET_TRANSPORT_TransmitReadyNotify notify,
534                                         void *notify_cls);
535
536
537 /**
538  * Cancel the specified transmission-ready notification.
539  *
540  * @param th handle of the transmission notification request to cancel
541  */
542 void
543 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct GNUNET_TRANSPORT_TransmitHandle *th);
544
545
546 /**
547  * Function called whenever there is an update to the
548  * HELLO of this peer.
549  *
550  * @param cls closure
551  * @param hello our updated HELLO
552  */
553 typedef void
554 (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls,
555                                          const struct GNUNET_MessageHeader *hello);
556
557
558 /**
559  * Handle to cancel a #GNUNET_TRANSPORT_get_hello() operation.
560  */
561 struct GNUNET_TRANSPORT_GetHelloHandle;
562
563
564 /**
565  * Checks if a given peer is connected to us
566  *
567  * @param handle connection to transport service
568  * @param peer the peer to check
569  * @return #GNUNET_YES (connected) or #GNUNET_NO (disconnected)
570  */
571 int
572 GNUNET_TRANSPORT_check_peer_connected (struct GNUNET_TRANSPORT_Handle *handle,
573                                        const struct GNUNET_PeerIdentity *peer);
574
575
576 /**
577  * Set transport metrics for a peer and a direction
578  *
579  * @param handle transport handle
580  * @param peer the peer to set the metric for
581  * @param inbound set inbound direction (#GNUNET_YES or #GNUNET_NO)
582  * @param outbound set outbound direction (#GNUNET_YES or #GNUNET_NO)
583  * @param ats the metric as ATS information
584  * @param ats_count the number of metrics
585  *
586  * Supported ATS values:
587  * #GNUNET_ATS_QUALITY_NET_DELAY  (value in ms)
588  * #GNUNET_ATS_QUALITY_NET_DISTANCE (value in count(hops))
589  *
590  * Example
591  * To enforce a delay of 10 ms for peer p1 in sending direction use:
592  *
593  * struct GNUNET_ATS_Information ats;
594  * ats.type = ntohl (GNUNET_ATS_QUALITY_NET_DELAY);
595  * ats.value = ntohl (10);
596  * GNUNET_TRANSPORT_set_traffic_metric (th, p1, TM_SEND, &ats, 1);
597  *
598  * Note:
599  * Delay restrictions in receiving direction will be enforced with
600  * 1 message delay.
601  */
602 void
603 GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
604                                      const struct GNUNET_PeerIdentity *peer,
605                                      int inbound,
606                                      int outbound,
607                                      const struct GNUNET_ATS_Information *ats,
608                                      size_t ats_count);
609
610
611 /**
612  * Obtain updates on changes to the HELLO message for this peer. The callback
613  * given in this function is never called synchronously.
614  *
615  * @param handle connection to transport service
616  * @param rec function to call with the HELLO
617  * @param rec_cls closure for @a rec
618  * @return handle to cancel the operation
619  */
620 struct GNUNET_TRANSPORT_GetHelloHandle *
621 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
622                             GNUNET_TRANSPORT_HelloUpdateCallback rec,
623                             void *rec_cls);
624
625
626 /**
627  * Stop receiving updates about changes to our HELLO message.
628  *
629  * @param ghh handle to cancel
630  */
631 void
632 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
633
634
635 /**
636  * Handle for a #GNUNET_TRANSPORT_offer_hello operation
637  */
638 struct GNUNET_TRANSPORT_OfferHelloHandle;
639
640 /**
641  * Offer the transport service the HELLO of another peer.  Note that
642  * the transport service may just ignore this message if the HELLO is
643  * malformed or useless due to our local configuration.
644  *
645  * @param handle connection to transport service
646  * @param hello the hello message
647  * @param cont continuation to call when HELLO has been sent,
648  *      tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail
649  *      tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success
650  * @param cls closure for continuation
651  * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure,
652  *      in case of failure cont will not be called
653  *
654  */
655 struct GNUNET_TRANSPORT_OfferHelloHandle *
656 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
657                               const struct GNUNET_MessageHeader *hello,
658                               GNUNET_SCHEDULER_Task cont, void *cls);
659
660
661 /**
662  * Cancel the request to transport to offer the HELLO message
663  *
664  * @param ohh the `struct GNUNET_TRANSPORT_OfferHelloHandle` to cancel
665  */
666 void
667 GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
668
669
670 /**
671  * Handle to cancel a pending address lookup.
672  */
673 struct GNUNET_TRANSPORT_AddressToStringContext;
674
675
676 /**
677  * Convert a binary address into a human readable address.
678  *
679  * @param cfg configuration to use
680  * @param address address to convert (binary format)
681  * @param numeric should (IP) addresses be displayed in numeric form
682  *                (otherwise do reverse DNS lookup)
683  * @param timeout how long is the lookup allowed to take at most
684  * @param aluc function to call with the results
685  * @param aluc_cls closure for @a aluc
686  * @return handle to cancel the operation, NULL on error
687  */
688 struct GNUNET_TRANSPORT_AddressToStringContext *
689 GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
690                                     const struct GNUNET_HELLO_Address *address,
691                                     int numeric,
692                                     struct GNUNET_TIME_Relative timeout,
693                                     GNUNET_TRANSPORT_AddressToStringCallback aluc,
694                                     void *aluc_cls);
695
696
697 /**
698  * Cancel request for address conversion.
699  *
700  * @param pic the context handle
701  */
702 void
703 GNUNET_TRANSPORT_address_to_string_cancel (struct GNUNET_TRANSPORT_AddressToStringContext *pic);
704
705
706 /**
707  * Convert a transport state to a human readable string.
708  *
709  * @param state the state
710  */
711 const char *
712 GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state);
713
714
715 /**
716  * Check if a state is defined as connected
717  *
718  * @param state the state value
719  * @return #GNUNET_YES or #GNUNET_NO
720  */
721 int
722 GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state);
723
724
725 /**
726  * Convert validation state to human-readable string.
727  *
728  * @param state the state value
729  * @return corresponding string
730  */
731 const char *
732 GNUNET_TRANSPORT_vs2s (enum GNUNET_TRANSPORT_ValidationState state);
733
734
735 /**
736  * Handle for a #GNUNET_TRANSPORT_monitor_peers operation.
737  */
738 struct GNUNET_TRANSPORT_PeerMonitoringContext;
739
740 /**
741  * Return information about a specific peer or all peers currently known to
742  * transport service once or in monitoring mode. To obtain information about
743  * a specific peer, a peer identity can be passed. To obtain information about
744  * all peers currently known to transport service, NULL can be passed as peer
745  * identity.
746  *
747  * For each peer, the callback is called with information about the address used
748  * to communicate with this peer, the state this peer is currently in and the
749  * the current timeout for this state.
750  *
751  * Upon completion, the 'GNUNET_TRANSPORT_PeerIterateCallback' is called one
752  * more time with 'NULL'. After this, the operation must no longer be
753  * explicitly canceled.
754  *
755  * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called in the
756  * the peer_callback!
757  *
758  * @param cfg configuration to use
759  * @param peer a specific peer identity to obtain information for,
760  *      NULL for all peers
761  * @param one_shot #GNUNET_YES to return the current state and then end (with NULL+NULL),
762  *                 #GNUNET_NO to monitor peers continuously
763  * @param timeout how long is the lookup allowed to take at most
764  * @param peer_callback function to call with the results
765  * @param peer_callback_cls closure for @a peer_callback
766  */
767 struct GNUNET_TRANSPORT_PeerMonitoringContext *
768 GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
769                                 const struct GNUNET_PeerIdentity *peer,
770                                 int one_shot,
771                                 struct GNUNET_TIME_Relative timeout,
772                                 GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
773                                 void *peer_callback_cls);
774
775
776 /**
777  * Cancel request to monitor peers
778  *
779  * @param pic handle for the request to cancel
780  */
781 void
782 GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic);
783
784
785 /**
786  * Handle for a #GNUNET_TRANSPORT_monitor_validation_entries() operation.
787  */
788 struct GNUNET_TRANSPORT_ValidationMonitoringContext;
789
790 /**
791  * Return information about pending address validation operations for a specific
792  * or all peers
793  *
794  * @param cfg configuration to use
795  * @param peer a specific peer identity to obtain validation entries for,
796  *      NULL for all peers
797  * @param one_shot #GNUNET_YES to return all entries and then end (with NULL+NULL),
798  *                 #GNUNET_NO to monitor validation entries continuously
799  * @param timeout how long is the lookup allowed to take at most
800  * @param validation_callback function to call with the results
801  * @param validation_callback_cls closure for @a validation_callback
802  */
803 struct GNUNET_TRANSPORT_ValidationMonitoringContext *
804 GNUNET_TRANSPORT_monitor_validation_entries (const struct GNUNET_CONFIGURATION_Handle *cfg,
805                                              const struct GNUNET_PeerIdentity *peer,
806                                              int one_shot,
807                                              struct GNUNET_TIME_Relative timeout,
808                                              GNUNET_TRANSPORT_ValidationIterateCallback validation_callback,
809                                              void *validation_callback_cls);
810
811
812 /**
813  * Return information about all current pending validation operations
814  *
815  * @param vic handle for the request to cancel
816  */
817 void
818 GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic);
819
820
821 /**
822  * Handle for blacklisting peers.
823  */
824 struct GNUNET_TRANSPORT_Blacklist;
825
826
827 /**
828  * Function that decides if a connection is acceptable or not.
829  *
830  * @param cls closure
831  * @param pid peer to approve or disapproave
832  * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
833  */
834 typedef int
835 (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls,
836                                        const struct
837                                        GNUNET_PeerIdentity * pid);
838
839
840 /**
841  * Install a blacklist callback.  The service will be queried for all
842  * existing connections as well as any fresh connections to check if
843  * they are permitted.  If the blacklisting callback is unregistered,
844  * all hosts that were denied in the past will automatically be
845  * whitelisted again.  Cancelling the blacklist handle is also the
846  * only way to re-enable connections from peers that were previously
847  * blacklisted.
848  *
849  * @param cfg configuration to use
850  * @param cb callback to invoke to check if connections are allowed
851  * @param cb_cls closure for @a cb
852  * @return NULL on error, otherwise handle for cancellation
853  */
854 struct GNUNET_TRANSPORT_Blacklist *
855 GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
856                             GNUNET_TRANSPORT_BlacklistCallback cb,
857                             void *cb_cls);
858
859
860 /**
861  * Abort the blacklist.  Note that this function is the only way for
862  * removing a peer from the blacklist.
863  *
864  * @param br handle of the request that is to be cancelled
865  */
866 void
867 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
868
869
870
871 #if 0                           /* keep Emacsens' auto-indent happy */
872 {
873 #endif
874 #ifdef __cplusplus
875 }
876 #endif
877
878 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
879 #endif
880 /* end of gnunet_transport_service.h */
881
882