29f5aeb0fd8d4a6f5216a8614f46d52cd1c2e7fa
[oweals/gnunet.git] / src / include / gnunet_vpn_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012 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
19 /**
20  * @author Christian Grothoff
21  *
22  * @file
23  * API to access the VPN service.
24  *
25  * @defgroup vpn  VPN service
26  *
27  * @{
28  */
29 #ifndef GNUNET_VPN_SERVICE_H
30 #define GNUNET_VPN_SERVICE_H
31
32 #include "gnunet_util_lib.h"
33
34
35 /**
36  * Opaque VPN handle
37  */
38 struct GNUNET_VPN_Handle;
39
40 /**
41  * Opaque redirection request handle.
42  */
43 struct GNUNET_VPN_RedirectionRequest;
44
45
46 /**
47  * Callback invoked from the VPN service once a redirection is
48  * available.  Provides the IP address that can now be used to
49  * reach the requested destination.
50  *
51  * @param cls closure
52  * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error;
53  *                will match 'result_af' from the request
54  * @param address IP address (struct in_addr or struct in_addr6, depending on 'af')
55  *                that the VPN allocated for the redirection;
56  *                traffic to this IP will now be redirected to the
57  *                specified target peer; NULL on error
58  */
59 typedef void (*GNUNET_VPN_AllocationCallback)(void *cls,
60                                               int af,
61                                               const void *address);
62
63
64 /**
65  * Cancel redirection request with the service.
66  *
67  * @param rr request to cancel
68  */
69 void
70 GNUNET_VPN_cancel_request (struct GNUNET_VPN_RedirectionRequest *rr);
71
72
73 /**
74  * Tell the VPN that a forwarding to a particular peer offering a
75  * particular service is requested.  The VPN is to reserve a
76  * particular IP for the redirection and return it.  The VPN will
77  * begin the redirection as soon as possible and maintain it as long
78  * as it is actively used and keeping it is feasible.  Given resource
79  * limitations, the longest inactive mappings will be destroyed.
80  *
81  * @param vh VPN handle
82  * @param result_af desired address family for the returned allocation
83  *                  can also be AF_UNSPEC
84  * @param protocol protocol, IPPROTO_UDP or IPPROTO_TCP
85  * @param peer target peer for the redirection
86  * @param serv service descriptor to give to the peer
87  * @param expiration_time at what time should the redirection expire?
88  *        (this should not impact connections that are active at that time)
89  * @param cb function to call with the IP
90  * @param cb_cls closure for cb
91  * @return handle to cancel the request (means the callback won't be
92  *         invoked anymore; the mapping may or may not be established
93  *         anyway)
94  */
95 struct GNUNET_VPN_RedirectionRequest *
96 GNUNET_VPN_redirect_to_peer (struct GNUNET_VPN_Handle *vh,
97                              int result_af,
98                              uint8_t protocol,
99                              const struct GNUNET_PeerIdentity *peer,
100                              const struct GNUNET_HashCode *serv,
101                              struct GNUNET_TIME_Absolute expiration_time,
102                              GNUNET_VPN_AllocationCallback cb,
103                              void *cb_cls);
104
105
106 /**
107  * Tell the VPN that forwarding to the Internet via some exit node is
108  * requested.  Note that both UDP and TCP traffic will be forwarded,
109  * but possibly to different exit nodes.  The VPN is to reserve a
110  * particular IP for the redirection and return it.  The VPN will
111  * begin the redirection as soon as possible and maintain it as long
112  * as it is actively used and keeping it is feasible.  Given resource
113  * limitations, the longest inactive mappings will be destroyed.
114  *
115  * @param vh VPN handle
116  * @param result_af desired address family for the returned allocation,
117  *                  can also be AF_UNSPEC
118  * @param addr_af address family for 'addr', AF_INET or AF_INET6
119  * @param addr destination IP address on the Internet; destination
120  *             port is to be taken from the VPN packet itself
121  * @param expiration_time at what time should the redirection expire?
122  *        (this should not impact connections that are active at that time)
123  * @param cb function to call with the IP
124  * @param cb_cls closure for cb
125  * @return handle to cancel the request (means the callback won't be
126  *         invoked anymore; the mapping may or may not be established
127  *         anyway)
128  */
129 struct GNUNET_VPN_RedirectionRequest *
130 GNUNET_VPN_redirect_to_ip (struct GNUNET_VPN_Handle *vh,
131                            int result_af,
132                            int addr_af,
133                            const void *addr,
134                            struct GNUNET_TIME_Absolute expiration_time,
135                            GNUNET_VPN_AllocationCallback cb,
136                            void *cb_cls);
137
138
139 /**
140  * Connect to the VPN service
141  *
142  * @param cfg configuration to use
143  * @return VPN handle
144  */
145 struct GNUNET_VPN_Handle *
146 GNUNET_VPN_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
147
148
149 /**
150  * Disconnect from the VPN service.
151  *
152  * @param vh VPN handle
153  */
154 void
155 GNUNET_VPN_disconnect (struct GNUNET_VPN_Handle *vh);
156
157 #endif
158
159 /** @} */  /* end of group */