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