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