add API for address injection
[oweals/gnunet.git] / src / include / gnunet_transport_hello_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009-2016 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21 /**
22  * @author Christian Grothoff
23  *
24  * @file
25  * obtain information about our current address
26  *
27  * @defgroup transport  Transport service
28  * address information
29  *
30  * @see [Documentation](https://gnunet.org/transport-service)
31  *
32  * @{
33  */
34 #ifndef GNUNET_TRANSPORT_HELLO_SERVICE_H
35 #define GNUNET_TRANSPORT_HELLO_SERVICE_H
36
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #if 0                           /* keep Emacsens' auto-indent happy */
41 }
42 #endif
43 #endif
44
45 #include "gnunet_util_lib.h"
46 #include "gnunet_ats_service.h"
47
48 /**
49  * Version number of the transport API.
50  */
51 #define GNUNET_TRANSPORT_HELLO_VERSION 0x00000000
52
53
54 /**
55  * Some addresses contain sensitive information or are
56  * not suitable for global distribution.  We use address
57  * classes to filter addresses by which domain they make
58  * sense to be used in.  These are used in a bitmask.
59  */
60 enum GNUNET_TRANSPORT_AddressClass
61 {
62
63   /**
64    * No address.
65    */
66   GNUNET_TRANSPORT_AC_NONE = 0,
67
68   /**
69    * Addresses that fall into no other category
70    * (i.e. incoming which we cannot use elsewhere).
71    */
72   GNUNET_TRANSPORT_AC_OTHER = 1,
73
74   /**
75    * Addresses that are global and are insensitive
76    * (i.e. IPv4).
77    */
78   GNUNET_TRANSPORT_AC_GLOBAL = 2,
79
80   /**
81    * Addresses that are global and are sensitive
82    * (i.e. IPv6 with our MAC).
83    */
84   GNUNET_TRANSPORT_AC_GLOBAL_PRIVATE = 4,
85
86   /**
87    * Addresses useful in the local wired network,
88    * i.e. a MAC.  Sensitive, but obvious to people nearby.
89    * Useful for broadcasts.
90    */
91   GNUNET_TRANSPORT_AC_LAN = 8,
92
93   /**
94    * Addresses useful in the local wireless network,
95    * i.e. a MAC.  Sensitive, but obvious to people nearby.
96    * Useful for broadcasts.
97    */
98   GNUNET_TRANSPORT_AC_WLAN = 16,
99
100   /**
101    * Addresses useful in the local bluetooth network.  Sensitive, but
102    * obvious to people nearby.  Useful for broadcasts.
103    */
104   GNUNET_TRANSPORT_AC_BT = 32,
105
106   /**
107    * Bitmask for "any" address.
108    */
109   GNUNET_TRANSPORT_AC_ANY = 65535
110
111 };
112
113
114 /**
115  * Function called whenever there is an update to the
116  * HELLO of this peer.
117  *
118  * @param cls closure
119  * @param hello our updated HELLO
120  */
121 typedef void
122 (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls,
123                                          const struct GNUNET_MessageHeader *hello);
124
125
126 /**
127  * Handle to cancel a #GNUNET_TRANSPORT_hello_get() operation.
128  */
129 struct GNUNET_TRANSPORT_HelloGetHandle;
130
131
132 /**
133  * Obtain updates on changes to the HELLO message for this peer. The callback
134  * given in this function is never called synchronously.
135  *
136  * @param cfg configuration to use
137  * @param ac which network type should the addresses from the HELLO belong to?
138  * @param rec function to call with the HELLO
139  * @param rec_cls closure for @a rec
140  * @return handle to cancel the operation
141  */
142 struct GNUNET_TRANSPORT_HelloGetHandle *
143 GNUNET_TRANSPORT_hello_get (const struct GNUNET_CONFIGURATION_Handle *cfg,
144                             enum GNUNET_TRANSPORT_AddressClass ac,
145                             GNUNET_TRANSPORT_HelloUpdateCallback rec,
146                             void *rec_cls);
147
148
149 /**
150  * Stop receiving updates about changes to our HELLO message.
151  *
152  * @param ghh handle to cancel
153  */
154 void
155 GNUNET_TRANSPORT_hello_get_cancel (struct GNUNET_TRANSPORT_HelloGetHandle *ghh);
156
157
158 /**
159  * Function with addresses found in a HELLO.
160  *
161  * @param cls closure
162  * @param peer identity of the peer
163  * @param address the address (UTF-8, 0-terminated)
164  * @param nt network type of the address
165  * @param expiration when does this address expire?
166  */
167 typedef void
168 (*GNUNET_TRANSPORT_AddressCallback) (void *cls,
169                                      const struct GNUNET_PeerIdentity *peer,
170                                      const char *address,
171                                      enum GNUNET_NetworkType nt,
172                                      struct GNUNET_TIME_Absolute expiration);
173
174
175 /**
176  * Parse a HELLO message that we have received into its
177  * constituent addresses.
178  *
179  * @param hello message to parse
180  * @param cb function to call on each address found
181  * @param cb_cls closure for @a cb
182  * @return #GNUNET_OK if hello was well-formed, #GNUNET_SYSERR if not
183  */
184 int
185 GNUNET_TRANSPORT_hello_parse (const struct GNUNET_MessageHeader *hello,
186                               GNUNET_TRANSPORT_AddressCallback cb,
187                               void *cb_cls);
188
189
190 #if 0                           /* keep Emacsens' auto-indent happy */
191 {
192 #endif
193 #ifdef __cplusplus
194 }
195 #endif
196
197 /* ifndef GNUNET_TRANSPORT_HELLO_SERVICE_H */
198 #endif
199
200 /** @} */  /* end of group */
201
202 /* end of gnunet_transport_hello_service.h */