2 This file is part of GNUnet.
3 Copyright (C) 2009-2014 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file include/gnunet_transport_service.h
23 * @brief low-level P2P IO
24 * @author Christian Grothoff
27 #ifndef GNUNET_TRANSPORT_SERVICE_H
28 #define GNUNET_TRANSPORT_SERVICE_H
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_util_lib.h"
39 #include "gnunet_ats_service.h"
42 * Version number of the transport API.
44 #define GNUNET_TRANSPORT_VERSION 0x00000002
48 * Function called by the transport for each received message.
51 * @param peer (claimed) identity of the other peer
52 * @param message the message
55 (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
56 const struct GNUNET_PeerIdentity *peer,
57 const struct GNUNET_MessageHeader *message);
61 * Opaque handle to the service.
63 struct GNUNET_TRANSPORT_Handle;
67 * Function called to notify transport users that another
68 * peer connected to us.
71 * @param peer the peer that connected
74 (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
75 const struct GNUNET_PeerIdentity *peer);
78 * Function called to notify transport users that another
79 * peer disconnected from us.
82 * @param peer the peer that disconnected
85 (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
86 const struct GNUNET_PeerIdentity *peer);
90 * Connect to the transport service. Note that the connection may
91 * complete (or fail) asynchronously.
93 * @param cfg configuration to use
94 * @param self our own identity (API should check that it matches
95 * the identity found by transport), or NULL (no check)
96 * @param cls closure for the callbacks
97 * @param rec receive function to call, or NULL
98 * @param nc function to call on connect events, or NULL
99 * @param nd function to call on disconnect events, or NULL
100 * @return NULL on error
102 struct GNUNET_TRANSPORT_Handle *
103 GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
104 const struct GNUNET_PeerIdentity *self,
106 GNUNET_TRANSPORT_ReceiveCallback rec,
107 GNUNET_TRANSPORT_NotifyConnect nc,
108 GNUNET_TRANSPORT_NotifyDisconnect nd);
112 * Function called if we have "excess" bandwidth to a peer.
113 * The notification will happen the first time we have excess
114 * bandwidth, and then only again after the client has performed
115 * some transmission to the peer.
117 * Excess bandwidth is defined as being allowed (by ATS) to send
118 * more data, and us reaching the limit of the capacity build-up
119 * (which, if we go past it, means we don't use available bandwidth).
120 * See also the "max carry" in `struct GNUNET_BANDWIDTH_Tracker`.
122 * @param cls the closure
123 * @param neighbour peer that we have excess bandwidth to
126 (*GNUNET_TRANSPORT_NotifyExcessBandwidth)(void *cls,
127 const struct GNUNET_PeerIdentity *neighbour);
131 * Connect to the transport service. Note that the connection may
132 * complete (or fail) asynchronously.
134 * @param cfg configuration to use
135 * @param self our own identity (API should check that it matches
136 * the identity found by transport), or NULL (no check)
137 * @param cls closure for the callbacks
138 * @param rec receive function to call, or NULL
139 * @param nc function to call on connect events, or NULL
140 * @param nd function to call on disconnect events, or NULL
141 * @param neb function to call if we have excess bandwidth to a peer
142 * @return NULL on error
144 struct GNUNET_TRANSPORT_Handle *
145 GNUNET_TRANSPORT_connect2 (const struct GNUNET_CONFIGURATION_Handle *cfg,
146 const struct GNUNET_PeerIdentity *self,
148 GNUNET_TRANSPORT_ReceiveCallback rec,
149 GNUNET_TRANSPORT_NotifyConnect nc,
150 GNUNET_TRANSPORT_NotifyDisconnect nd,
151 GNUNET_TRANSPORT_NotifyExcessBandwidth neb);
155 * Disconnect from the transport service.
157 * @param handle handle returned from connect
160 GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
163 /* ************************* Connections *********************** */
166 * Opaque handle for a transmission-ready request.
168 struct GNUNET_TRANSPORT_TryConnectHandle;
171 * Function to call with result of the try connect request.
174 * @param result #GNUNET_OK if message was transmitted to transport service
175 * #GNUNET_SYSERR if message was not transmitted to transport service
178 (*GNUNET_TRANSPORT_TryConnectCallback) (void *cls,
183 * Ask the transport service to establish a connection to
186 * @param handle connection to transport service
187 * @param target who we should try to connect to
188 * @param cb callback to be called when request was transmitted to transport
190 * @param cb_cls closure for the callback @a cb
191 * @return a `struct GNUNET_TRANSPORT_TryConnectHandle` handle or
192 * NULL on failure (@a cb will not be called)
194 struct GNUNET_TRANSPORT_TryConnectHandle *
195 GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
196 const struct GNUNET_PeerIdentity *target,
197 GNUNET_TRANSPORT_TryConnectCallback cb,
202 * Cancel the request to transport to try a connect
203 * Callback will not be called
205 * @param tch handle to cancel
208 GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch);
212 * Opaque handle for a transmission-ready request.
214 struct GNUNET_TRANSPORT_TryDisconnectHandle;
217 * Function to call with result of the try connect request.
220 * @param result #GNUNET_OK if message was transmitted to transport service
221 * #GNUNET_SYSERR if message was not transmitted to transport service
224 (*GNUNET_TRANSPORT_TryDisconnectCallback) (void *cls,
229 * Ask the transport service to disconnect from the given peer.
231 * @param handle connection to transport service
232 * @param target who we should try to disconnect from
233 * @param cb callback to be called when request was transmitted to transport
235 * @param cb_cls closure for the callback @a cb
236 * @return a `struct GNUNET_TRANSPORT_TryConnectHandle` handle or
237 * NULL on failure (@a cb will not be called)
239 struct GNUNET_TRANSPORT_TryDisconnectHandle *
240 GNUNET_TRANSPORT_try_disconnect (struct GNUNET_TRANSPORT_Handle *handle,
241 const struct GNUNET_PeerIdentity *target,
242 GNUNET_TRANSPORT_TryDisconnectCallback cb,
247 * Cancel the request to transport to disconnect.
248 * Callback will not be called anymore.
250 * @param tdh handle for operation to cancel
253 GNUNET_TRANSPORT_try_disconnect_cancel (struct GNUNET_TRANSPORT_TryDisconnectHandle *tdh);
256 /* ************************* Sending *************************** */
259 * Opaque handle for a transmission-ready request.
261 struct GNUNET_TRANSPORT_TransmitHandle;
265 * Function called to notify a client about the connection begin ready
266 * to queue more data. @a buf will be NULL and @a size zero if the
267 * connection was closed for writing in the meantime.
270 * @param size number of bytes available in @a buf
271 * @param buf where the callee should write the message
272 * @return number of bytes written to @a buf
275 (*GNUNET_TRANSPORT_TransmitReadyNotify) (void *cls,
281 * Check if we could queue a message of the given size for
282 * transmission. The transport service will take both its internal
283 * buffers and bandwidth limits imposed by the other peer into
284 * consideration when answering this query.
286 * @param handle connection to transport service
287 * @param target who should receive the message
288 * @param size how big is the message we want to transmit?
289 * @param timeout after how long should we give up (and call
290 * notify with buf NULL and size 0)?
291 * @param notify function to call when we are ready to
292 * send such a message
293 * @param notify_cls closure for @a notify
294 * @return NULL if someone else is already waiting to be notified
295 * non-NULL if the notify callback was queued (can be used to cancel
296 * using #GNUNET_TRANSPORT_notify_transmit_ready_cancel())
298 struct GNUNET_TRANSPORT_TransmitHandle *
299 GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
300 const struct GNUNET_PeerIdentity *target,
302 struct GNUNET_TIME_Relative timeout,
303 GNUNET_TRANSPORT_TransmitReadyNotify notify,
308 * Cancel the specified transmission-ready notification.
310 * @param th handle of the transmission notification request to cancel
313 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct GNUNET_TRANSPORT_TransmitHandle *th);
317 * Checks if a given peer is connected to us
319 * @param handle connection to transport service
320 * @param peer the peer to check
321 * @return #GNUNET_YES (connected) or #GNUNET_NO (disconnected)
324 GNUNET_TRANSPORT_check_peer_connected (struct GNUNET_TRANSPORT_Handle *handle,
325 const struct GNUNET_PeerIdentity *peer);
329 /* *********************** Metric manipulation ***************** */
332 * Set transport metrics for a peer and a direction
334 * @param handle transport handle
335 * @param peer the peer to set the metric for
336 * @param prop the performance metrics to set
337 * @param delay_in inbound delay to introduce
338 * @param delay_out outbound delay to introduce
340 * Note: Delay restrictions in receiving direction will be enforced
341 * with one message delay.
344 GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
345 const struct GNUNET_PeerIdentity *peer,
346 const struct GNUNET_ATS_Properties *prop,
347 struct GNUNET_TIME_Relative delay_in,
348 struct GNUNET_TIME_Relative delay_out);
351 /* *************************** HELLO *************************** */
355 * Function called whenever there is an update to the
356 * HELLO of this peer.
359 * @param hello our updated HELLO
362 (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls,
363 const struct GNUNET_MessageHeader *hello);
367 * Handle to cancel a #GNUNET_TRANSPORT_get_hello() operation.
369 struct GNUNET_TRANSPORT_GetHelloHandle;
373 * Obtain updates on changes to the HELLO message for this peer. The callback
374 * given in this function is never called synchronously.
376 * @param handle connection to transport service
377 * @param rec function to call with the HELLO
378 * @param rec_cls closure for @a rec
379 * @return handle to cancel the operation
381 struct GNUNET_TRANSPORT_GetHelloHandle *
382 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
383 GNUNET_TRANSPORT_HelloUpdateCallback rec,
388 * Stop receiving updates about changes to our HELLO message.
390 * @param ghh handle to cancel
393 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
397 * Handle for a #GNUNET_TRANSPORT_offer_hello operation
399 struct GNUNET_TRANSPORT_OfferHelloHandle;
403 * Offer the transport service the HELLO of another peer. Note that
404 * the transport service may just ignore this message if the HELLO is
405 * malformed or useless due to our local configuration.
407 * @param handle connection to transport service
408 * @param hello the hello message
409 * @param cont continuation to call when HELLO has been sent,
410 * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail
411 * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success
412 * @param cls closure for continuation
413 * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure,
414 * in case of failure cont will not be called
417 struct GNUNET_TRANSPORT_OfferHelloHandle *
418 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
419 const struct GNUNET_MessageHeader *hello,
420 GNUNET_SCHEDULER_TaskCallback cont, void *cls);
424 * Cancel the request to transport to offer the HELLO message
426 * @param ohh the `struct GNUNET_TRANSPORT_OfferHelloHandle` to cancel
429 GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
432 /* *********************** Address to String ******************* */
435 * Handle to cancel a pending address lookup.
437 struct GNUNET_TRANSPORT_AddressToStringContext;
441 * Function to call with a textual representation of an address. This
442 * function will be called several times with different possible
443 * textual representations, and a last time with @a address being NULL
444 * to signal the end of the iteration. Note that @a address NULL
445 * always is the last call, regardless of the value in @a res.
448 * @param address NULL on end of iteration,
449 * otherwise 0-terminated printable UTF-8 string,
450 * in particular an empty string if @a res is #GNUNET_NO
451 * @param res result of the address to string conversion:
452 * if #GNUNET_OK: conversion successful
453 * if #GNUNET_NO: address was invalid (or not supported)
454 * if #GNUNET_SYSERR: communication error (IPC error)
457 (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
463 * Convert a binary address into a human readable address.
465 * @param cfg configuration to use
466 * @param address address to convert (binary format)
467 * @param numeric should (IP) addresses be displayed in numeric form
468 * (otherwise do reverse DNS lookup)
469 * @param timeout how long is the lookup allowed to take at most
470 * @param aluc function to call with the results
471 * @param aluc_cls closure for @a aluc
472 * @return handle to cancel the operation, NULL on error
474 struct GNUNET_TRANSPORT_AddressToStringContext *
475 GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
476 const struct GNUNET_HELLO_Address *address,
478 struct GNUNET_TIME_Relative timeout,
479 GNUNET_TRANSPORT_AddressToStringCallback aluc,
484 * Cancel request for address conversion.
486 * @param pic the context handle
489 GNUNET_TRANSPORT_address_to_string_cancel (struct GNUNET_TRANSPORT_AddressToStringContext *pic);
492 /* *********************** Monitoring ************************** */
496 * Possible state of a neighbour. Initially, we are #GNUNET_TRANSPORT_PS_NOT_CONNECTED.
498 * Then, there are two main paths. If we receive a SYN message, we give
499 * the inbound address to ATS. After the check we ask ATS for a suggestion
500 * (#GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS). If ATS makes a suggestion, we
501 * send our SYN_ACK and go to #GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK.
502 * If we receive a ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
503 * (and notify everyone about the new connection). If the operation times out,
504 * we go to #GNUNET_TRANSPORT_PS_DISCONNECT.
506 * The other case is where we transmit a SYN message first. We
507 * start with #GNUNET_TRANSPORT_PS_INIT_ATS. If we get an address, we send
508 * the SYN message and go to state #GNUNET_TRANSPORT_PS_CONNECT_SENT.
509 * Once we receive a SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
510 * (and notify everyone about the new connection and send
511 * back a ACK). If the operation times out, we go to
512 * #GNUNET_TRANSPORT_PS_DISCONNECT.
514 * If the session is in trouble (i.e. transport-level disconnect or
515 * timeout), we go to #GNUNET_TRANSPORT_PS_RECONNECT_ATS where we ask ATS for a new
516 * address (we don't notify anyone about the disconnect yet). Once we
517 * have a new address, we enter #GNUNET_TRANSPORT_PS_RECONNECT_SENT and send a
518 * SYN message. If we receive a
519 * SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED and nobody noticed that we had
520 * trouble; we also send a ACK at this time just in case. If
521 * the operation times out, we go to #GNUNET_TRANSPORT_PS_DISCONNECT (and notify everyone
522 * about the lost connection).
524 * If ATS decides to switch addresses while we have a normal
525 * connection, we go to #GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_SYN_SENT
526 * and send a SESSION_CONNECT. If we get a ACK back, we switch the
527 * primary connection to the suggested alternative from ATS, go back
528 * to #GNUNET_TRANSPORT_PS_CONNECTED and send a ACK to the other peer just to be
529 * sure. If the operation times out
530 * we go to #GNUNET_TRANSPORT_PS_CONNECTED (and notify ATS that the given alternative
531 * address is "invalid").
533 * Once a session is in #GNUNET_TRANSPORT_PS_DISCONNECT, it is cleaned up and then goes
534 * to (#GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED). If we receive an explicit disconnect
535 * request, we can go from any state to #GNUNET_TRANSPORT_PS_DISCONNECT, possibly after
536 * generating disconnect notifications.
538 * Note that it is quite possible that while we are in any of these
539 * states, we could receive a 'SYN' request from the other peer.
540 * We then enter a 'weird' state where we pursue our own primary state
541 * machine (as described above), but with the 'send_connect_ack' flag
542 * set to 1. If our state machine allows us to send a 'SYN_ACK'
543 * (because we have an acceptable address), we send the 'SYN_ACK'
544 * and set the 'send_connect_ack' to 2. If we then receive a
545 * 'ACK', we go to #GNUNET_TRANSPORT_PS_CONNECTED (and reset 'send_connect_ack'
549 enum GNUNET_TRANSPORT_PeerState
552 * Fresh peer or completely disconnected
554 GNUNET_TRANSPORT_PS_NOT_CONNECTED = 0,
557 * Asked to initiate connection, trying to get address from ATS
559 GNUNET_TRANSPORT_PS_INIT_ATS,
562 * Sent SYN message to other peer, waiting for SYN_ACK
564 GNUNET_TRANSPORT_PS_SYN_SENT,
567 * Received a SYN, asking ATS about address suggestions.
569 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
572 * SYN request from other peer was SYN_ACK'ed, waiting for ACK.
574 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
577 * Got our SYN_ACK/ACK, connection is up.
579 GNUNET_TRANSPORT_PS_CONNECTED,
582 * Connection got into trouble, rest of the system still believes
583 * it to be up, but we're getting a new address from ATS.
585 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
588 * Sent SYN over new address (either by ATS telling us to switch
589 * addresses or from RECONNECT_ATS); if this fails, we need to tell
590 * the rest of the system about a disconnect.
592 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
595 * We have some primary connection, but ATS suggested we switch
596 * to some alternative; we now sent a SYN message for the
597 * alternative session to the other peer and waiting for a
598 * SYN_ACK to make this our primary connection.
600 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
603 * Disconnect in progress (we're sending the DISCONNECT message to the
604 * other peer; after that is finished, the state will be cleaned up).
606 GNUNET_TRANSPORT_PS_DISCONNECT,
609 * We're finished with the disconnect; and are cleaning up the state
610 * now! We put the struct into this state when we are really in the
611 * task that calls 'free' on it and are about to remove the record
612 * from the map. We should never find a 'struct NeighbourMapEntry'
613 * in this state in the map. Accessing a 'struct NeighbourMapEntry'
614 * in this state virtually always means using memory that has been
615 * freed (the exception being the cleanup code in #free_neighbour()).
617 GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED
622 * Convert a transport state to a human readable string.
624 * @param state the state
627 GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state);
631 * Check if a state is defined as connected
633 * @param state the state value
634 * @return #GNUNET_YES or #GNUNET_NO
637 GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state);
641 * Handle for a #GNUNET_TRANSPORT_monitor_peers operation.
643 struct GNUNET_TRANSPORT_PeerMonitoringContext;
647 * Function to call with information about a peer
649 * If one_shot was set to #GNUNET_YES to iterate over all peers once,
650 * a final call with NULL for peer and address will follow when done.
651 * In this case state and timeout do not contain valid values.
653 * The #GNUNET_TRANSPORT_monitor_peers_cancel() call MUST not be called from
654 * within this function!
658 * @param peer peer this update is about,
659 * NULL if this is the final last callback for a iteration operation
660 * @param address address, NULL if this is the final callback for iteration op
661 * @param state current state this peer is in
662 * @param state_timeout timeout for the current state of the peer
665 (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
666 const struct GNUNET_PeerIdentity *peer,
667 const struct GNUNET_HELLO_Address *address,
668 enum GNUNET_TRANSPORT_PeerState state,
669 struct GNUNET_TIME_Absolute state_timeout);
673 * Return information about a specific peer or all peers currently known to
674 * transport service once or in monitoring mode. To obtain information about
675 * a specific peer, a peer identity can be passed. To obtain information about
676 * all peers currently known to transport service, NULL can be passed as peer
679 * For each peer, the callback is called with information about the address used
680 * to communicate with this peer, the state this peer is currently in and the
681 * the current timeout for this state.
683 * Upon completion, the #GNUNET_TRANSPORT_PeerIterateCallback is called one
684 * more time with `NULL`. After this, the operation must no longer be
685 * explicitly canceled.
687 * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called in the
690 * @param cfg configuration to use
691 * @param peer a specific peer identity to obtain information for,
693 * @param one_shot #GNUNET_YES to return the current state and then end (with NULL+NULL),
694 * #GNUNET_NO to monitor peers continuously
695 * @param timeout how long is the lookup allowed to take at most
696 * @param peer_callback function to call with the results
697 * @param peer_callback_cls closure for @a peer_callback
699 struct GNUNET_TRANSPORT_PeerMonitoringContext *
700 GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
701 const struct GNUNET_PeerIdentity *peer,
703 struct GNUNET_TIME_Relative timeout,
704 GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
705 void *peer_callback_cls);
709 * Cancel request to monitor peers
711 * @param pic handle for the request to cancel
714 GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic);
718 * Handle for a #GNUNET_TRANSPORT_monitor_validation_entries() operation.
720 struct GNUNET_TRANSPORT_ValidationMonitoringContext;
724 * Current state of a validation process.
726 * FIXME: what state is used to indicate that a validation
727 * was successful? If that is clarified/determined, "UGH" in
728 * ~gnunet-peerinfo-gtk.c:1103 should be resolved.
730 enum GNUNET_TRANSPORT_ValidationState
735 * Used for final callback indicating operation done
737 GNUNET_TRANSPORT_VS_NONE,
740 * Fresh validation entry
742 * Entry was just created, no validation process was executed
744 GNUNET_TRANSPORT_VS_NEW,
747 * Updated validation entry
749 * This is an update for an existing validation entry
751 GNUNET_TRANSPORT_VS_UPDATE,
754 * Timeout for validation entry
756 * A timeout occured during the validation process
758 GNUNET_TRANSPORT_VS_TIMEOUT,
761 * Validation entry is removed
763 * The validation entry is getting removed due to a failed validation
765 GNUNET_TRANSPORT_VS_REMOVE
770 * Function to call with validation information about a peer
772 * This function is called by the transport validation monitoring api to
773 * indicate a change to a validation entry. The information included represent
774 * the current state of the validation entry,
776 * If the monitoring was called with `one_shot==GNUNET_YES`, a final callback
777 * with `address==NULL` is executed.
780 * @param address address this update is about,
781 * NULL if this is the final last callback for a iteration operation
782 * @param last_validation when was this address last validated
783 * @param valid_until when does this address expire
784 * @param next_validation time of the next validation operation
785 * @param state state in the validation state machine
788 (*GNUNET_TRANSPORT_ValidationIterateCallback) (void *cls,
789 const struct GNUNET_HELLO_Address *address,
790 struct GNUNET_TIME_Absolute last_validation,
791 struct GNUNET_TIME_Absolute valid_until,
792 struct GNUNET_TIME_Absolute next_validation,
793 enum GNUNET_TRANSPORT_ValidationState state);
797 * Convert validation state to human-readable string.
799 * @param state the state value
800 * @return corresponding string
803 GNUNET_TRANSPORT_vs2s (enum GNUNET_TRANSPORT_ValidationState state);
807 * Return information about pending address validation operations for a specific
810 * @param cfg configuration to use
811 * @param peer a specific peer identity to obtain validation entries for,
813 * @param one_shot #GNUNET_YES to return all entries and then end (with NULL+NULL),
814 * #GNUNET_NO to monitor validation entries continuously
815 * @param timeout how long is the lookup allowed to take at most
816 * @param validation_callback function to call with the results
817 * @param validation_callback_cls closure for @a validation_callback
819 struct GNUNET_TRANSPORT_ValidationMonitoringContext *
820 GNUNET_TRANSPORT_monitor_validation_entries (const struct GNUNET_CONFIGURATION_Handle *cfg,
821 const struct GNUNET_PeerIdentity *peer,
823 struct GNUNET_TIME_Relative timeout,
824 GNUNET_TRANSPORT_ValidationIterateCallback validation_callback,
825 void *validation_callback_cls);
829 * Return information about all current pending validation operations
831 * @param vic handle for the request to cancel
834 GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic);
837 /* *********************** Blacklisting ************************ */
840 * Handle for blacklisting peers.
842 struct GNUNET_TRANSPORT_Blacklist;
846 * Function that decides if a connection is acceptable or not.
849 * @param pid peer to approve or disapproave
850 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
853 (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls,
854 const struct GNUNET_PeerIdentity *pid);
858 * Install a blacklist callback. The service will be queried for all
859 * existing connections as well as any fresh connections to check if
860 * they are permitted. If the blacklisting callback is unregistered,
861 * all hosts that were denied in the past will automatically be
862 * whitelisted again. Cancelling the blacklist handle is also the
863 * only way to re-enable connections from peers that were previously
866 * @param cfg configuration to use
867 * @param cb callback to invoke to check if connections are allowed
868 * @param cb_cls closure for @a cb
869 * @return NULL on error, otherwise handle for cancellation
871 struct GNUNET_TRANSPORT_Blacklist *
872 GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
873 GNUNET_TRANSPORT_BlacklistCallback cb,
878 * Abort the blacklist. Note that this function is the only way for
879 * removing a peer from the blacklist.
881 * @param br handle of the request that is to be cancelled
884 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
888 * Handle for a plugin session state monitor.
890 struct GNUNET_TRANSPORT_PluginMonitor;
893 * Abstract representation of a plugin's session.
894 * Corresponds to the `struct Session` within the TRANSPORT service.
896 struct GNUNET_TRANSPORT_PluginSession;
900 * Possible states of a session in a plugin.
902 enum GNUNET_TRANSPORT_SessionState
906 * The session was created (first call for each session object).
908 GNUNET_TRANSPORT_SS_INIT,
911 * Initial session handshake is in progress.
913 GNUNET_TRANSPORT_SS_HANDSHAKE,
916 * Session is fully UP.
918 GNUNET_TRANSPORT_SS_UP,
921 * This is just an update about the session,
922 * the state did not change.
924 GNUNET_TRANSPORT_SS_UPDATE,
927 * Session is being torn down and about to disappear.
928 * Last call for each session object.
930 GNUNET_TRANSPORT_SS_DONE
936 * Information about a plugin's session.
938 struct GNUNET_TRANSPORT_SessionInfo
942 * New state of the session.
944 enum GNUNET_TRANSPORT_SessionState state;
947 * #GNUNET_YES if this is an inbound connection,
948 * #GNUNET_NO if this is an outbound connection,
949 * #GNUNET_SYSERR if connections of this plugin
950 * are so fundamentally bidirectional
951 * that they have no 'initiator'
956 * Number of messages pending transmission for this session.
958 uint32_t num_msg_pending;
961 * Number of bytes pending transmission for this session.
963 uint32_t num_bytes_pending;
966 * Until when does this plugin refuse to receive to manage
967 * staying within the inbound quota? ZERO if receive is
970 struct GNUNET_TIME_Absolute receive_delay;
973 * At what time will this session timeout (unless activity
976 struct GNUNET_TIME_Absolute session_timeout;
979 * Address used by the session. Can be NULL if none is available.
981 const struct GNUNET_HELLO_Address *address;
986 * Function called by the plugin with information about the
987 * current sessions managed by the plugin (for monitoring).
990 * @param session session handle this information is about,
991 * NULL to indicate that we are "in sync" (initial
992 * iteration complete)
993 * @param session_ctx storage location where the application
994 * can store data; will point to NULL on #GNUNET_TRANSPORT_SS_INIT,
995 * and must be reset to NULL on #GNUNET_TRANSPORT_SS_DONE
996 * @param info information about the state of the session,
997 * NULL if @a session is also NULL and we are
998 * merely signalling that the initial iteration is over;
999 * NULL with @a session being non-NULL if the monitor
1000 * was being cancelled while sessions were active
1003 (*GNUNET_TRANSPORT_SessionMonitorCallback) (void *cls,
1004 struct GNUNET_TRANSPORT_PluginSession *session,
1006 const struct GNUNET_TRANSPORT_SessionInfo *info);
1010 * Install a plugin session state monitor callback. The callback
1011 * will be notified whenever the session changes.
1013 * @param cfg configuration to use
1014 * @param cb callback to invoke on events
1015 * @param cb_cls closure for @a cb
1016 * @return NULL on error, otherwise handle for cancellation
1018 struct GNUNET_TRANSPORT_PluginMonitor *
1019 GNUNET_TRANSPORT_monitor_plugins (const struct GNUNET_CONFIGURATION_Handle *cfg,
1020 GNUNET_TRANSPORT_SessionMonitorCallback cb,
1025 * Cancel monitoring the plugin session state. The callback will be
1026 * called once for each session that is up with the "info" argument
1027 * being NULL (this is just to enable client-side cleanup).
1029 * @param pm handle of the request that is to be cancelled
1032 GNUNET_TRANSPORT_monitor_plugins_cancel (struct GNUNET_TRANSPORT_PluginMonitor *pm);
1036 #if 0 /* keep Emacsens' auto-indent happy */
1043 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
1045 /* end of gnunet_transport_service.h */