0d6e0ef5aeed2fb02e40ebad18e99a924eacfd35
[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 last_validated_at is FOREVER if the address has not been validated (we're currently checking)
107  *                          is ZERO if the address was validated a long time ago (from PEERINFO)
108  *                          is a time in the past if this process validated the address
109  * @param validation_block  is FOREVER if the address is for an unsupported plugin (from PEERINFO)
110  *                          is ZERO if the address is considered valid (no validation needed)
111  *                          is a time in the future if we're currently denying re-validation
112  * @param plugin_name name of the plugin
113  * @param plugin_address binary address
114  * @param plugin_address_len length of address
115  */
116 typedef void (*GST_ValidationAddressCallback)(void *cls,
117                                               const struct GNUNET_PeerIdentity *target,
118                                               struct GNUNET_TIME_Absolute last_validated_at,
119                                               struct GNUNET_TIME_Absolute validation_block,
120                                               const char *plugin_name,
121                                               const void *plugin_address,
122                                               size_t plugin_address_len);
123
124
125 /**
126  * Call the given function for each address for the given target.
127  * Can either give a snapshot (synchronous API) or be continuous.
128  *
129  * @param target peer information is requested for
130  * @param snapshot_only GNUNET_YES to iterate over addresses once, GNUNET_NO to
131  *                      continue to give information about addresses as it evolves
132  * @param cb function to call; will not be called after this function returns
133  *                             if snapshot_only is GNUNET_YES
134  * @param cb_cls closure for 'cb'
135  * @return context to cancel, NULL if 'snapshot_only' is GNUNET_YES
136  */
137 struct GST_ValidationIteratorContext *
138 GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
139                               int snapshot_only,
140                               GST_ValidationAddressCallback cb,
141                               void *cb_cls);
142
143
144 /**
145  * Cancel an active validation address iteration.
146  *
147  * @param ctx the context of the operation that is cancelled
148  */
149 void
150 GST_validation_get_addresses_cancel (struct GST_ValidationIteratorContext *ctx);
151
152
153
154 #endif
155 /* end of file gnunet-service-transport_validation.h */