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