2 This file is part of GNUnet.
3 (C) 2010,2011 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file transport/gnunet-service-transport_validation.h
23 * @brief address validation API
24 * @author Christian Grothoff
26 #ifndef GNUNET_SERVICE_TRANSPORT_VALIDATION_H
27 #define GNUNET_SERVICE_TRANSPORT_VALIDATION_H
29 #include "gnunet_statistics_service.h"
30 #include "gnunet_transport_plugin.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_hello_lib.h"
35 * Function called to notify transport users that a neighbour peer changed its
39 * @param peer peer this update is about (never NULL)
40 * @param address address (never NULL)
41 * @param last_validation point in time when last validation was performed
42 * @param valid_until point in time how long address is valid
43 * @param next_validation point in time when next validation will be performed
44 * @param state state of validation notification
46 typedef void (*GST_ValidationChangedCallback) (void *cls,
47 const struct GNUNET_PeerIdentity *peer,
48 const struct GNUNET_HELLO_Address *address,
49 struct GNUNET_TIME_Absolute last_validation,
50 struct GNUNET_TIME_Absolute valid_until,
51 struct GNUNET_TIME_Absolute next_validation,
52 enum GNUNET_TRANSPORT_ValidationState state);
55 * Start the validation subsystem.
57 * @param max_fds maximum number of fds to use
60 GST_validation_start (GST_ValidationChangedCallback cb, void *cb_cls, unsigned int max_fds);
64 * Stop the validation subsystem.
67 GST_validation_stop (void);
71 * Update if we are using an address for a connection actively right now.
72 * Based on this, the validation module will measure latency for the
73 * address more or less often.
75 * @param address the address
76 * @param session the session
77 * @param in_use GNUNET_YES if we are now using the address for a connection,
78 * GNUNET_NO if we are no longer using the address for a connection
81 GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address,
82 struct Session *session,
87 * Query validation about the latest observed latency on a given
91 * @param address the address
92 * @param session session
93 * @return observed latency of the address, FOREVER if the address was
94 * never successfully validated
96 struct GNUNET_TIME_Relative
97 GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender,
98 const struct GNUNET_HELLO_Address *address,
99 struct Session *session);
102 * Iterate over all iteration entries
104 * @param cb function to call
105 * @param cb_cls closure for cb
108 GST_validation_iterate (GST_ValidationChangedCallback cb, void *cb_cls);
111 * We've received a PING. If appropriate, generate a PONG.
113 * @param sender peer sending the PING
114 * @param hdr the PING
115 * @param sender_address address of the sender, NULL if we did not initiate
116 * @param session session we got the PING from
117 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
120 GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
121 const struct GNUNET_MessageHeader *hdr,
122 const struct GNUNET_HELLO_Address *sender_address,
123 struct Session *session);
127 * We've received a PONG. Check if it matches a pending PING and
128 * mark the respective address as confirmed.
130 * @param sender peer sending the PONG
131 * @param hdr the PONG
132 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
135 GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
136 const struct GNUNET_MessageHeader *hdr);
140 * We've received a HELLO, check which addresses are new and trigger
143 * @param hello the HELLO we received
144 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
147 GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
151 * Function called for each address (or address status change) that
152 * the validation module is aware of (for the given target).
155 * @param public_key public key for the peer, never NULL
156 * @param valid_until is ZERO if we never validated the address,
157 * otherwise a time up to when we consider it (or was) valid
158 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
159 * is ZERO if the address is considered valid (no validation needed)
160 * otherwise a time in the future if we're currently denying re-validation
161 * @param address the address
163 typedef void (*GST_ValidationAddressCallback) (void *cls,
165 GNUNET_CRYPTO_EddsaPublicKey *public_key,
166 struct GNUNET_TIME_Absolute
168 struct GNUNET_TIME_Absolute
170 const struct GNUNET_HELLO_Address
175 * Call the given function for each address for the given target.
177 * @param target peer information is requested for
178 * @param cb function to call; will not be called after this function returns
179 * @param cb_cls closure for 'cb'
182 GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
183 GST_ValidationAddressCallback cb, void *cb_cls);
187 /* end of file gnunet-service-transport_validation.h */