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