get_address_latency also does not use session
[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  * Start the validation subsystem.
36  *
37  * @param max_fds maximum number of fds to use
38  */
39 void
40 GST_validation_start (unsigned int max_fds);
41
42
43 /**
44  * Stop the validation subsystem.
45  */
46 void
47 GST_validation_stop (void);
48
49
50 /**
51  * Update if we are using an address for a connection actively right now.
52  * Based on this, the validation module will measure latency for the
53  * address more or less often.
54  *
55  * @param address the address that we are now using (or not)
56  * @param in_use #GNUNET_YES if we are now using the address for a connection,
57  *               #GNUNET_NO if we are no longer using the address for a connection
58  */
59 void
60 GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address,
61                                 int in_use);
62
63
64 /**
65  * Query validation about the latest observed latency on a given
66  * address.
67  *
68  * @param address the address
69  * @return observed latency of the address, FOREVER if the address was
70  *         never successfully validated
71  */
72 struct GNUNET_TIME_Relative
73 GST_validation_get_address_latency (const struct GNUNET_HELLO_Address *address);
74
75
76 /**
77  * Function called to notify transport users that a neighbour peer changed its
78  * active address.
79  *
80  * @param cls closure
81  * @param address address (never NULL)
82  * @param last_validation point in time when last validation was performed
83  * @param valid_until point in time how long address is valid
84  * @param next_validation point in time when next validation will be performed
85  * @param state state of validation notification
86  */
87 typedef void
88 (*GST_ValidationChangedCallback) (void *cls,
89                                   const struct GNUNET_HELLO_Address *address,
90                                   struct GNUNET_TIME_Absolute last_validation,
91                                   struct GNUNET_TIME_Absolute valid_until,
92                                   struct GNUNET_TIME_Absolute next_validation,
93                                   enum GNUNET_TRANSPORT_ValidationState state);
94
95
96 /**
97  * Iterate over all iteration entries
98  *
99  * @param cb function to call
100  * @param cb_cls closure for @a cb
101  */
102 void
103 GST_validation_iterate (GST_ValidationChangedCallback cb, void *cb_cls);
104
105
106 /**
107  * We've received a PING.  If appropriate, generate a PONG.
108  *
109  * @param sender peer sending the PING
110  * @param hdr the PING
111  * @param sender_address address of the sender, NULL if we did not initiate
112  * @param session session we got the PING from
113  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
114  */
115 int
116 GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
117                             const struct GNUNET_MessageHeader *hdr,
118                             const struct GNUNET_HELLO_Address *sender_address,
119                             struct Session *session);
120
121
122 /**
123  * We've received a PONG.  Check if it matches a pending PING and
124  * mark the respective address as confirmed.
125  *
126  * @param sender peer sending the PONG
127  * @param hdr the PONG
128  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
129  */
130 int
131 GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
132                             const struct GNUNET_MessageHeader *hdr);
133
134
135 /**
136  * We've received a HELLO, check which addresses are new and trigger
137  * validation.
138  *
139  * @param hello the HELLO we received
140  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
141  */
142 int
143 GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
144
145
146 /**
147  * Function called for each address (or address status change) that
148  * the validation module is aware of (for the given target).
149  *
150  * @param cls closure
151  * @param public_key public key for the peer, never NULL
152  * @param valid_until is ZERO if we never validated the address,
153  *                    otherwise a time up to when we consider it (or was) valid
154  * @param validation_block  is FOREVER if the address is for an unsupported plugin (from PEERINFO)
155  *                          is ZERO if the address is considered valid (no validation needed)
156  *                          otherwise a time in the future if we're currently denying re-validation
157  * @param address the address
158  */
159 typedef void
160 (*GST_ValidationAddressCallback) (void *cls,
161                                   struct GNUNET_TIME_Absolute valid_until,
162                                   struct GNUNET_TIME_Absolute validation_block,
163                                   const struct GNUNET_HELLO_Address *address);
164
165
166 /**
167  * Call the given function for each address for the given target.
168  *
169  * @param target peer information is requested for
170  * @param cb function to call; will not be called after this function returns
171  * @param cb_cls closure for @a cb
172  */
173 void
174 GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
175                               GST_ValidationAddressCallback cb, void *cb_cls);
176
177
178 #endif
179 /* end of file gnunet-service-transport_validation.h */