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