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