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