- fix compilation
[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 #S_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 (#S_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 (S_CONNECT_RECV_ATS).
54  * If ATS makes a suggestion, we ALSO give that suggestion to the blacklist
55  * (#S_CONNECT_RECV_BLACKLIST).  Once the blacklist approves the
56  * address we got from ATS, we send our CONNECT_ACK and go to
57  * #S_CONNECT_RECV_ACK.  If we receive a SESSION_ACK, we go to
58  * #S_CONNECTED (and notify everyone about the new connection).  If the
59  * operation times out, we go to #S_DISCONNECT.
60  *
61  * The other case is where we transmit a CONNECT message first.  We
62  * start with #S_INIT_ATS.  If we get an address, we enter
63  * #S_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 S_CONNECT_SENT.  Once we receive a CONNECT_ACK, we go to
66  * #S_CONNECTED (and notify everyone about the new connection and send
67  * back a SESSION_ACK).  If the operation times out, we go to
68  * #S_DISCONNECT.
69  *
70  * If the session is in trouble (i.e. transport-level disconnect or
71  * timeout), we go to #S_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 #S_RECONNECT_BLACKLIST to check the new
74  * address against the blacklist.  If the blacklist approves, we enter
75  * #S_RECONNECT_SENT and send a CONNECT message.  If we receive a
76  * CONNECT_ACK, we go to #S_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 S_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 #S_CONNECTED_SWITCHING_BLACKLIST to check the
83  * new address against the blacklist.  If the blacklist approves, we
84  * go to #S_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 #S_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 #S_CONNECTED (and notify ATS that the given alternative
90  * address is "invalid").
91  *
92  * Once a session is in #S_DISCONNECT, it is cleaned up and then goes
93  * to (#S_DISCONNECT_FINISHED).  If we receive an explicit disconnect
94  * request, we can go from any state to #S_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 #S_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
211 /**
212  * Function called by the transport for each received message.
213  *
214  * @param cls closure
215  * @param peer (claimed) identity of the other peer
216  * @param message the message
217  * @param ats performance data
218  * @param ats_count number of entries in ats
219  */
220 typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
221                                                   const struct
222                                                   GNUNET_PeerIdentity * peer,
223                                                   const struct
224                                                   GNUNET_MessageHeader *
225                                                   message);
226
227
228 /**
229  * Opaque handle to the service.
230  */
231 struct GNUNET_TRANSPORT_Handle;
232
233
234 /**
235  * Function called to notify transport users that another
236  * peer connected to us.
237  *
238  * @param cls closure
239  * @param peer the peer that connected
240  * @param ats performance data
241  * @param ats_count number of entries in ats (excluding 0-termination)
242  */
243 typedef void (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
244                                                 const struct GNUNET_PeerIdentity
245                                                 * peer);
246
247 /**
248  * Function called to notify transport users that another
249  * peer disconnected from us.
250  *
251  * @param cls closure
252  * @param peer the peer that disconnected
253  */
254 typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
255                                                    const struct
256                                                    GNUNET_PeerIdentity * peer);
257
258
259 /**
260  * Function to call with result of the try connect request.
261  *
262  *
263  * @param cls closure
264  * @param result GNUNET_OK if message was transmitted to transport service
265  *               GNUNET_SYSERR if message was not transmitted to transport service
266  */
267 typedef void (*GNUNET_TRANSPORT_TryConnectCallback) (void *cls,
268                                                      const int result);
269
270
271 /**
272  * Function to call with a textual representation of an address.
273  * This function will be called several times with different possible
274  * textual representations, and a last time with NULL to signal the end
275  * of the iteration.
276  *
277  * @param cls closure
278  * @param address NULL on error or end of iteration,
279  *        otherwise 0-terminated printable UTF-8 string
280  */
281 typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
282                                                           const char *address);
283
284
285 /**
286  * Function to call with information about a peer
287  *
288  * If one_shot was set to GNUNET_YES to iterate over all peers once,
289  * a final call with NULL for peer and address will follow when done.
290  * In this case state and timeout do not contain valid values.
291  *
292  * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called from
293  * within this function!
294  *
295  *
296  * @param cls closure
297  * @param peer peer this update is about,
298  *      NULL if this is the final last callback for a iteration operation
299  * @param address address, NULL for disconnect notification in monitor mode
300  * @param state current state this peer is in
301  * @param state_timeout timeout for the current state of the peer
302  */
303 typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
304                                     const struct GNUNET_PeerIdentity *peer,
305                                     const struct GNUNET_HELLO_Address *address,
306                                     enum GNUNET_TRANSPORT_PeerState state,
307                                     struct GNUNET_TIME_Absolute state_timeout);
308
309
310 /**
311  * Function to call with validation information about a peer
312  *
313  * @param cls closure
314  * @param peer peer this update is about,
315  *      NULL if this is the final last callback for a iteration operation
316  * @param address address, NULL for disconnect notification in monitor mode
317  * @param valid_until when does this address expire
318  * @param next_validation time of the next validation operation
319  *
320  */
321 typedef void (*GNUNET_TRANSPORT_ValidationIterateCallback) (void *cls,
322                                     const struct GNUNET_PeerIdentity *peer,
323                                     const struct GNUNET_HELLO_Address *address,
324                                     struct GNUNET_TIME_Absolute valid_until,
325                                     struct GNUNET_TIME_Absolute next_validation);
326
327
328
329 /**
330  * Connect to the transport service.  Note that the connection may
331  * complete (or fail) asynchronously.
332  *
333  * @param cfg configuration to use
334  * @param self our own identity (API should check that it matches
335  *             the identity found by transport), or NULL (no check)
336  * @param cls closure for the callbacks
337  * @param rec receive function to call, or NULL
338  * @param nc function to call on connect events, or NULL
339  * @param nd function to call on disconnect events, or NULL
340  * @return NULL on error
341  */
342 struct GNUNET_TRANSPORT_Handle *
343 GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
344                           const struct GNUNET_PeerIdentity *self, void *cls,
345                           GNUNET_TRANSPORT_ReceiveCallback rec,
346                           GNUNET_TRANSPORT_NotifyConnect nc,
347                           GNUNET_TRANSPORT_NotifyDisconnect nd);
348
349
350 /**
351  * Disconnect from the transport service.
352  *
353  * @param handle handle returned from connect
354  */
355 void
356 GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
357
358
359 /**
360  * Opaque handle for a transmission-ready request.
361  */
362 struct GNUNET_TRANSPORT_TryConnectHandle;
363
364
365 /**
366  * Ask the transport service to establish a connection to
367  * the given peer.
368  *
369  * @param handle connection to transport service
370  * @param target who we should try to connect to
371  * @param cb callback to be called when request was transmitted to transport
372  *         service
373  * @param cb_cls closure for the callback
374  * @return a GNUNET_TRANSPORT_TryConnectHandle handle or
375  *         NULL on failure (cb will not be called)
376  */
377 struct GNUNET_TRANSPORT_TryConnectHandle *
378 GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
379                               const struct GNUNET_PeerIdentity *target,
380                               GNUNET_TRANSPORT_TryConnectCallback cb,
381                               void *cb_cls);
382
383
384 /**
385  * Cancel the request to transport to try a connect
386  * Callback will not be called
387  *
388  * @param tch GNUNET_TRANSPORT_TryConnectHandle handle to cancel
389  */
390 void
391 GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch);
392
393
394 /**
395  * Opaque handle for a transmission-ready request.
396  */
397 struct GNUNET_TRANSPORT_TransmitHandle;
398
399
400 /**
401  * Check if we could queue a message of the given size for
402  * transmission.  The transport service will take both its internal
403  * buffers and bandwidth limits imposed by the other peer into
404  * consideration when answering this query.
405  *
406  * @param handle connection to transport service
407  * @param target who should receive the message
408  * @param size how big is the message we want to transmit?
409  * @param priority how important is the message? @deprecated - remove?
410  * @param timeout after how long should we give up (and call
411  *        notify with buf NULL and size 0)?
412  * @param notify function to call when we are ready to
413  *        send such a message
414  * @param notify_cls closure for notify
415  * @return NULL if someone else is already waiting to be notified
416  *         non-NULL if the notify callback was queued (can be used to cancel
417  *         using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
418  */
419 struct GNUNET_TRANSPORT_TransmitHandle *
420 GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
421                                         const struct GNUNET_PeerIdentity
422                                         *target, size_t size, uint32_t priority,
423                                         struct GNUNET_TIME_Relative timeout,
424                                         GNUNET_CONNECTION_TransmitReadyNotify
425                                         notify, void *notify_cls);
426
427
428 /**
429  * Cancel the specified transmission-ready notification.
430  *
431  * @param th handle of the transmission notification request to cancel
432  */
433 void
434 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
435                                                GNUNET_TRANSPORT_TransmitHandle
436                                                *th);
437
438
439
440 /**
441  * Function called whenever there is an update to the
442  * HELLO of this peer.
443  *
444  * @param cls closure
445  * @param hello our updated HELLO
446  */
447 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls,
448                                                       const struct
449                                                       GNUNET_MessageHeader *
450                                                       hello);
451
452
453 /**
454  * Handle to cancel a 'GNUNET_TRANSPORT_get_hello' operation.
455  */
456 struct GNUNET_TRANSPORT_GetHelloHandle;
457
458
459 /**
460  * Checks if a given peer is connected to us
461  *
462  * @param handle connection to transport service
463  * @param peer the peer to check
464  * @return #GNUNET_YES (connected) or #GNUNET_NO (disconnected)
465  */
466 int
467 GNUNET_TRANSPORT_check_peer_connected (struct GNUNET_TRANSPORT_Handle *handle,
468                                             const struct GNUNET_PeerIdentity *peer);
469
470
471 /**
472  * Set transport metrics for a peer and a direction
473  *
474  * @param handle transport handle
475  * @param peer the peer to set the metric for
476  * @param inbound set inbound direction (GNUNET_YES or GNUNET_NO)
477  * @param outbound set outbound direction (GNUNET_YES or GNUNET_NO)
478  * @param ats the metric as ATS information
479  * @param ats_count the number of metrics
480  *
481  * Supported ATS values:
482  * GNUNET_ATS_QUALITY_NET_DELAY  (value in ms)
483  * GNUNET_ATS_QUALITY_NET_DISTANCE (value in count(hops))
484  *
485  * Example
486  * To enforce a delay of 10 ms for peer p1 in sending direction use:
487  *
488  * struct GNUNET_ATS_Information ats;
489  * ats.type = ntohl (GNUNET_ATS_QUALITY_NET_DELAY);
490  * ats.value = ntohl (10);
491  * GNUNET_TRANSPORT_set_traffic_metric (th, p1, TM_SEND, &ats, 1);
492  *
493  * Note:
494  * Delay restrictions in receiving direction will be enforced with
495  * 1 message delay.
496  */
497 void
498 GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
499                                      const struct GNUNET_PeerIdentity *peer,
500                                      int inbound,
501                                      int outbound,
502                                      const struct GNUNET_ATS_Information *ats,
503                                      size_t ats_count);
504
505
506 /**
507  * Obtain updates on changes to the HELLO message for this peer. The callback
508  * given in this function is never called synchronously.
509  *
510  * @param handle connection to transport service
511  * @param rec function to call with the HELLO
512  * @param rec_cls closure for rec
513  * @return handle to cancel the operation
514  */
515 struct GNUNET_TRANSPORT_GetHelloHandle *
516 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
517                             GNUNET_TRANSPORT_HelloUpdateCallback rec,
518                             void *rec_cls);
519
520
521 /**
522  * Stop receiving updates about changes to our HELLO message.
523  *
524  * @param ghh handle to cancel
525  */
526 void
527 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
528
529
530 /**
531  * Offer the transport service the HELLO of another peer.  Note that
532  * the transport service may just ignore this message if the HELLO is
533  * malformed or useless due to our local configuration.
534  *
535  * @param handle connection to transport service
536  * @param hello the hello message
537  * @param cont continuation to call when HELLO has been sent,
538  *      tc reason GNUNET_SCHEDULER_REASON_TIMEOUT for fail
539  *      tc reasong GNUNET_SCHEDULER_REASON_READ_READY for success
540  * @param cls closure for continuation
541  * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure,
542  *      in case of failure cont will not be called
543  *
544  */
545 struct GNUNET_TRANSPORT_OfferHelloHandle *
546 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
547                               const struct GNUNET_MessageHeader *hello,
548                               GNUNET_SCHEDULER_Task cont, void *cls);
549
550
551 /**
552  * Cancel the request to transport to offer the HELLO message
553  *
554  * @param ohh the GNUNET_TRANSPORT_OfferHelloHandle to cancel
555  */
556 void
557 GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
558
559
560 /**
561  * Handle to cancel a pending address lookup.
562  */
563 struct GNUNET_TRANSPORT_AddressToStringContext;
564
565
566 /**
567  * Convert a binary address into a human readable address.
568  *
569  * @param cfg configuration to use
570  * @param address address to convert (binary format)
571  * @param numeric should (IP) addresses be displayed in numeric form
572  *                (otherwise do reverse DNS lookup)
573  * @param timeout how long is the lookup allowed to take at most
574  * @param aluc function to call with the results
575  * @param aluc_cls closure for aluc
576  * @return handle to cancel the operation, NULL on error
577  */
578 struct GNUNET_TRANSPORT_AddressToStringContext *
579 GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle
580                                     *cfg,
581                                     const struct GNUNET_HELLO_Address *address,
582                                     int numeric,
583                                     struct GNUNET_TIME_Relative timeout,
584                                     GNUNET_TRANSPORT_AddressToStringCallback
585                                     aluc, void *aluc_cls);
586
587
588 /**
589  * Cancel request for address conversion.
590  *
591  * @param pic the context handle
592  */
593 void
594 GNUNET_TRANSPORT_address_to_string_cancel (struct
595                                            GNUNET_TRANSPORT_AddressToStringContext
596                                            *pic);
597
598 /**
599  * Convert a transport state to a human readable string.
600  *
601  * @param state the state
602  */
603 const char *
604 GNUNET_TRANSPORT_p2s (enum GNUNET_TRANSPORT_PeerState state);
605
606
607 /**
608  * Check if a state is defined as connected
609  *
610  * @param state the state value
611  * @return GNUNET_YES or GNUNET_NO
612  */
613 int
614 GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state);
615
616
617 /**
618  * Return information about a specific peer or all peers currently known to
619  * transport service once or in monitoring mode. To obtain information about
620  * a specific peer, a peer identity can be passed. To obtain information about
621  * all peers currently known to transport service, NULL can be passed as peer
622  * identity.
623  *
624  * For each peer, the callback is called with information about the address used
625  * to communicate with this peer, the state this peer is currently in and the
626  * the current timeout for this state.
627  *
628  * Upon completion, the 'GNUNET_TRANSPORT_PeerIterateCallback' is called one
629  * more time with 'NULL'. After this, the operation must no longer be
630  * explicitly canceled.
631  *
632  * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called in the
633  * the peer_callback!
634  *
635  * @param cfg configuration to use
636  * @param peer a specific peer identity to obtain information for,
637  *      NULL for all peers
638  * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL),
639  *                 GNUNET_NO to monitor peers continuously
640  * @param timeout how long is the lookup allowed to take at most
641  * @param peer_callback function to call with the results
642  * @param peer_callback_cls closure for peer_address_callback
643  */
644 struct GNUNET_TRANSPORT_PeerMonitoringContext *
645 GNUNET_TRANSPORT_monitor_peers (const struct
646                                 GNUNET_CONFIGURATION_Handle *cfg,
647                                 const struct GNUNET_PeerIdentity *peer,
648                                 int one_shot,
649                                 struct GNUNET_TIME_Relative timeout,
650                                 GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
651                                 void *peer_callback_cls);
652
653
654 /**
655  * Cancel request to monitor peers
656  *
657  * @param pic handle for the request to cancel
658  */
659 void
660 GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic);
661
662
663
664 /**
665  * Return information about pending address validation operations for a specific
666  * or all peers
667  *
668  * @param cfg configuration to use
669  * @param peer a specific peer identity to obtain validation entries for,
670  *      NULL for all peers
671  * @param one_shot GNUNET_YES to return all entries and then end (with NULL+NULL),
672  *                 GNUNET_NO to monitor validation entries continuously
673  * @param timeout how long is the lookup allowed to take at most
674  * @param validation_callback function to call with the results
675  * @param validation_callback_cls closure for peer_address_callback
676  */
677 struct GNUNET_TRANSPORT_ValidationMonitoringContext *
678 GNUNET_TRANSPORT_monitor_validation_entries (const struct
679                                 GNUNET_CONFIGURATION_Handle *cfg,
680                                 const struct GNUNET_PeerIdentity *peer,
681                                 int one_shot,
682                                 struct GNUNET_TIME_Relative timeout,
683                                 GNUNET_TRANSPORT_ValidationIterateCallback validation_callback,
684                                 void *validation_callback_cls);
685
686
687 /**
688  * Return information about all current pending validation operations
689  *
690  * @param vic handle for the request to cancel
691  */
692 void
693 GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic);
694
695
696
697 /**
698  * Handle for blacklisting peers.
699  */
700 struct GNUNET_TRANSPORT_Blacklist;
701
702
703 /**
704  * Function that decides if a connection is acceptable or not.
705  *
706  * @param cls closure
707  * @param pid peer to approve or disapproave
708  * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not
709  */
710 typedef int (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls,
711                                                    const struct
712                                                    GNUNET_PeerIdentity * pid);
713
714
715 /**
716  * Install a blacklist callback.  The service will be queried for all
717  * existing connections as well as any fresh connections to check if
718  * they are permitted.  If the blacklisting callback is unregistered,
719  * all hosts that were denied in the past will automatically be
720  * whitelisted again.  Cancelling the blacklist handle is also the
721  * only way to re-enable connections from peers that were previously
722  * blacklisted.
723  *
724  * @param cfg configuration to use
725  * @param cb callback to invoke to check if connections are allowed
726  * @param cb_cls closure for cb
727  * @return NULL on error, otherwise handle for cancellation
728  */
729 struct GNUNET_TRANSPORT_Blacklist *
730 GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
731                             GNUNET_TRANSPORT_BlacklistCallback cb,
732                             void *cb_cls);
733
734
735 /**
736  * Abort the blacklist.  Note that this function is the only way for
737  * removing a peer from the blacklist.
738  *
739  * @param br handle of the request that is to be cancelled
740  */
741 void
742 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
743
744
745
746 #if 0                           /* keep Emacsens' auto-indent happy */
747 {
748 #endif
749 #ifdef __cplusplus
750 }
751 #endif
752
753 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
754 #endif
755 /* end of gnunet_transport_service.h */