-allow caller ID to differ from zone used for resolution
[oweals/gnunet.git] / src / transport / gnunet-service-transport_validation.h
1 /*
2      This file is part of GNUnet.
3      (C) 2010,2011 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file transport/gnunet-service-transport_validation.h
23  * @brief address validation API
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_SERVICE_TRANSPORT_VALIDATION_H
27 #define GNUNET_SERVICE_TRANSPORT_VALIDATION_H
28
29 #include "gnunet_statistics_service.h"
30 #include "gnunet_transport_plugin.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_hello_lib.h"
33
34 /**
35  * Function called to notify transport users that a neighbour peer changed its
36  * active address.
37  *
38  * @param cls closure
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
45  */
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);
53
54
55 /**
56  * Start the validation subsystem.
57  *
58  * @param cb callback to call with changes to valdidation entries
59  * @param cb_cls cls for the callback
60  * @param max_fds maximum number of fds to use
61  */
62 void
63 GST_validation_start (GST_ValidationChangedCallback cb, void *cb_cls, unsigned int max_fds);
64
65
66 /**
67  * Stop the validation subsystem.
68  */
69 void
70 GST_validation_stop (void);
71
72
73 /**
74  * Update if we are using an address for a connection actively right now.
75  * Based on this, the validation module will measure latency for the
76  * address more or less often.
77  *
78  * @param address the address
79  * @param session the session
80  * @param in_use GNUNET_YES if we are now using the address for a connection,
81  *               GNUNET_NO if we are no longer using the address for a connection
82  */
83 void
84 GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address,
85                                 struct Session *session,
86                                 int in_use);
87
88
89 /**
90  * Query validation about the latest observed latency on a given
91  * address.
92  *
93  * @param sender peer
94  * @param address the address
95  * @param session session
96  * @return observed latency of the address, FOREVER if the address was
97  *         never successfully validated
98  */
99 struct GNUNET_TIME_Relative
100 GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender,
101                                     const struct GNUNET_HELLO_Address *address,
102                                     struct Session *session);
103
104 /**
105  * Iterate over all iteration entries
106  *
107  * @param cb function to call
108  * @param cb_cls closure for cb
109  */
110 void
111 GST_validation_iterate (GST_ValidationChangedCallback cb, void *cb_cls);
112
113 /**
114  * We've received a PING.  If appropriate, generate a PONG.
115  *
116  * @param sender peer sending the PING
117  * @param hdr the PING
118  * @param sender_address address of the sender, NULL if we did not initiate
119  * @param session session we got the PING from
120  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
121  */
122 int
123 GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
124                             const struct GNUNET_MessageHeader *hdr,
125                             const struct GNUNET_HELLO_Address *sender_address,
126                             struct Session *session);
127
128
129 /**
130  * We've received a PONG.  Check if it matches a pending PING and
131  * mark the respective address as confirmed.
132  *
133  * @param sender peer sending the PONG
134  * @param hdr the PONG
135  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
136  */
137 int
138 GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
139                             const struct GNUNET_MessageHeader *hdr);
140
141
142 /**
143  * We've received a HELLO, check which addresses are new and trigger
144  * validation.
145  *
146  * @param hello the HELLO we received
147  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
148  */
149 int
150 GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
151
152
153 /**
154  * Function called for each address (or address status change) that
155  * the validation module is aware of (for the given target).
156  *
157  * @param cls closure
158  * @param public_key public key for the peer, never NULL
159  * @param valid_until is ZERO if we never validated the address,
160  *                    otherwise a time up to when we consider it (or was) valid
161  * @param validation_block  is FOREVER if the address is for an unsupported plugin (from PEERINFO)
162  *                          is ZERO if the address is considered valid (no validation needed)
163  *                          otherwise a time in the future if we're currently denying re-validation
164  * @param address the address
165  */
166 typedef void (*GST_ValidationAddressCallback) (void *cls,
167                                                const struct
168                                                GNUNET_CRYPTO_EddsaPublicKey *public_key,
169                                                struct GNUNET_TIME_Absolute
170                                                valid_until,
171                                                struct GNUNET_TIME_Absolute
172                                                validation_block,
173                                                const struct GNUNET_HELLO_Address
174                                                * address);
175
176
177 /**
178  * Call the given function for each address for the given target.
179  *
180  * @param target peer information is requested for
181  * @param cb function to call; will not be called after this function returns
182  * @param cb_cls closure for 'cb'
183  */
184 void
185 GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
186                               GST_ValidationAddressCallback cb, void *cb_cls);
187
188
189 #endif
190 /* end of file gnunet-service-transport_validation.h */