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