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