avoid passing both PeerIdentity and Address (which contains PeerIdentity) if address...
[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
56  * @param session the session
57  * @param in_use #GNUNET_YES if we are now using the address for a connection,
58  *               #GNUNET_NO if we are no longer using the address for a connection
59  */
60 void
61 GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address,
62                                 struct Session *session,
63                                 int in_use);
64
65
66 /**
67  * Query validation about the latest observed latency on a given
68  * address.
69  *
70  * @param address the address
71  * @param session session
72  * @return observed latency of the address, FOREVER if the address was
73  *         never successfully validated
74  */
75 struct GNUNET_TIME_Relative
76 GST_validation_get_address_latency (const struct GNUNET_HELLO_Address *address,
77                                     struct Session *session);
78
79
80 /**
81  * Function called to notify transport users that a neighbour peer changed its
82  * active address.
83  *
84  * @param cls closure
85  * @param address address (never NULL)
86  * @param last_validation point in time when last validation was performed
87  * @param valid_until point in time how long address is valid
88  * @param next_validation point in time when next validation will be performed
89  * @param state state of validation notification
90  */
91 typedef void
92 (*GST_ValidationChangedCallback) (void *cls,
93                                   const struct GNUNET_HELLO_Address *address,
94                                   struct GNUNET_TIME_Absolute last_validation,
95                                   struct GNUNET_TIME_Absolute valid_until,
96                                   struct GNUNET_TIME_Absolute next_validation,
97                                   enum GNUNET_TRANSPORT_ValidationState state);
98
99
100 /**
101  * Iterate over all iteration entries
102  *
103  * @param cb function to call
104  * @param cb_cls closure for @a cb
105  */
106 void
107 GST_validation_iterate (GST_ValidationChangedCallback cb, void *cb_cls);
108
109
110 /**
111  * We've received a PING.  If appropriate, generate a PONG.
112  *
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
118  */
119 int
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);
124
125
126 /**
127  * We've received a PONG.  Check if it matches a pending PING and
128  * mark the respective address as confirmed.
129  *
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
133  */
134 int
135 GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
136                             const struct GNUNET_MessageHeader *hdr);
137
138
139 /**
140  * We've received a HELLO, check which addresses are new and trigger
141  * validation.
142  *
143  * @param hello the HELLO we received
144  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
145  */
146 int
147 GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
148
149
150 /**
151  * Function called for each address (or address status change) that
152  * the validation module is aware of (for the given target).
153  *
154  * @param cls closure
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
162  */
163 typedef void
164 (*GST_ValidationAddressCallback) (void *cls,
165                                   struct GNUNET_TIME_Absolute valid_until,
166                                   struct GNUNET_TIME_Absolute validation_block,
167                                   const struct GNUNET_HELLO_Address *address);
168
169
170 /**
171  * Call the given function for each address for the given target.
172  *
173  * @param target peer information is requested for
174  * @param cb function to call; will not be called after this function returns
175  * @param cb_cls closure for @a cb
176  */
177 void
178 GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
179                               GST_ValidationAddressCallback cb, void *cb_cls);
180
181
182 #endif
183 /* end of file gnunet-service-transport_validation.h */