218b45457408ab4fa94d86947d2e0aaa56595526
[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_util_lib.h"
31
32
33 /**
34  * Start the validation subsystem.
35  */
36 void 
37 GST_validation_start (void);
38
39
40 /**
41  * Stop the validation subsystem.
42  */
43 void
44 GST_validation_stop (void);
45
46
47 /**
48  * We've received a PING.  If appropriate, generate a PONG.
49  *
50  * @param sender peer sending the PING
51  * @param hdr the PING
52  * @param plugin_name name of plugin that received the PING
53  * @param sender_address address of the sender as known to the plugin, NULL
54  *                       if we did not initiate the connection
55  * @param sender_address_len number of bytes in sender_address
56  */
57 void
58 GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
59                             const struct GNUNET_MessageHeader *hdr,
60                             const char *plugin_name,
61                             const void *sender_address,
62                             size_t sender_address_len);
63
64
65 /**
66  * We've received a PONG.  Check if it matches a pending PING and
67  * mark the respective address as confirmed.
68  *
69  * @param sender peer sending the PONG
70  * @param hdr the PONG
71  * @param plugin_name name of plugin that received the PONG
72  * @param sender_address address of the sender as known to the plugin, NULL
73  *                       if we did not initiate the connection
74  * @param sender_address_len number of bytes in sender_address
75  */
76 void
77 GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
78                             const struct GNUNET_MessageHeader *hdr,
79                             const char *plugin_name,
80                             const void *sender_address,
81                             size_t sender_address_len);
82
83
84 /**
85  * We've received a HELLO, check which addresses are new and trigger
86  * validation.
87  *
88  * @param hello the HELLO we received
89  */
90 void
91 GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
92
93
94 /**
95  * Opaque handle to stop incremental validation address callbacks.
96  */
97 struct GST_ValidationIteratorContext;
98
99
100 /**
101  * Function called for each address (or address status change) that
102  * the validation module is aware of (for the given target).
103  *
104  * @param cls closure
105  * @param target peer this change is about, never NULL
106  * @param valid_until is ZERO if we never validated the address,
107  *                    otherwise a time up to when we consider it (or was) valid
108  * @param validation_block  is FOREVER if the address is for an unsupported plugin (from PEERINFO)
109  *                          is ZERO if the address is considered valid (no validation needed)
110  *                          otherwise a time in the future if we're currently denying re-validation
111  * @param plugin_name name of the plugin
112  * @param plugin_address binary address
113  * @param plugin_address_len length of address
114  */
115 typedef void (*GST_ValidationAddressCallback)(void *cls,
116                                               const struct GNUNET_PeerIdentity *target,
117                                               struct GNUNET_TIME_Absolute valid_until,
118                                               struct GNUNET_TIME_Absolute validation_block,
119                                               const char *plugin_name,
120                                               const void *plugin_address,
121                                               size_t plugin_address_len);
122
123
124 /**
125  * Call the given function for each address for the given target.
126  * Can either give a snapshot (synchronous API) or be continuous.
127  *
128  * @param target peer information is requested for
129  * @param snapshot_only GNUNET_YES to iterate over addresses once, GNUNET_NO to
130  *                      continue to give information about addresses as it evolves
131  * @param cb function to call; will not be called after this function returns
132  *                             if snapshot_only is GNUNET_YES
133  * @param cb_cls closure for 'cb'
134  * @return context to cancel, NULL if 'snapshot_only' is GNUNET_YES
135  */
136 struct GST_ValidationIteratorContext *
137 GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
138                               int snapshot_only,
139                               GST_ValidationAddressCallback cb,
140                               void *cb_cls);
141
142
143 /**
144  * Cancel an active validation address iteration.
145  *
146  * @param ctx the context of the operation that is cancelled
147  */
148 void
149 GST_validation_get_addresses_cancel (struct GST_ValidationIteratorContext *ctx);
150
151
152
153 #endif
154 /* end of file gnunet-service-transport_validation.h */