aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-16 09:44:58 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-16 09:44:58 +0000
commitc0cf6345215b55c20a5d84ae0604e499845ee989 (patch)
tree8443f444c5fa9f4710b85323f4d070fcce905afb /src
parentdab580c6caa8106f45d7fcd51329d51df6a792eb (diff)
downloadgnunet-c0cf6345215b55c20a5d84ae0604e499845ee989.tar.gz
gnunet-c0cf6345215b55c20a5d84ae0604e499845ee989.zip
Add VPN resolution
Diffstat (limited to 'src')
-rw-r--r--src/gns/Makefile.am4
-rw-r--r--src/gns/gnunet-service-gns_resolver.c245
-rw-r--r--src/gns/gnunet-service-gns_resolver.h6
-rw-r--r--src/include/gnunet_gns_service.h3
4 files changed, 246 insertions, 12 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 2e5aa193a..a65ab994b 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -226,6 +226,7 @@ gnunet_service_gns_LDADD = \
226 $(top_builddir)/src/dns/libgnunetdnsparser.la \ 226 $(top_builddir)/src/dns/libgnunetdnsparser.la \
227 $(top_builddir)/src/dht/libgnunetdht.la \ 227 $(top_builddir)/src/dht/libgnunetdht.la \
228 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 228 $(top_builddir)/src/namestore/libgnunetnamestore.la \
229 $(top_builddir)/src/vpn/libgnunetvpn.la \
229 $(GN_LIBINTL) 230 $(GN_LIBINTL)
230gnunet_service_gns_DEPENDENCIES = \ 231gnunet_service_gns_DEPENDENCIES = \
231 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 232 $(top_builddir)/src/statistics/libgnunetstatistics.la \
@@ -233,7 +234,8 @@ gnunet_service_gns_DEPENDENCIES = \
233 $(top_builddir)/src/dns/libgnunetdns.la \ 234 $(top_builddir)/src/dns/libgnunetdns.la \
234 $(top_builddir)/src/dns/libgnunetdnsparser.la \ 235 $(top_builddir)/src/dns/libgnunetdnsparser.la \
235 $(top_builddir)/src/dht/libgnunetdht.la \ 236 $(top_builddir)/src/dht/libgnunetdht.la \
236 $(top_builddir)/src/namestore/libgnunetnamestore.la 237 $(top_builddir)/src/namestore/libgnunetnamestore.la \
238 $(top_builddir)/src/vpn/libgnunetvpn.la
237 239
238 240
239gnunet_gns_fcfsd_SOURCES = \ 241gnunet_gns_fcfsd_SOURCES = \
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 3d58c33f6..6e20c3f9c 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -31,6 +31,7 @@
31#include "gnunet_dns_service.h" 31#include "gnunet_dns_service.h"
32#include "gnunet_dht_service.h" 32#include "gnunet_dht_service.h"
33#include "gnunet_namestore_service.h" 33#include "gnunet_namestore_service.h"
34#include "gnunet_vpn_service.h"
34#include "gnunet_dns_service.h" 35#include "gnunet_dns_service.h"
35#include "gnunet_dnsparser_lib.h" 36#include "gnunet_dnsparser_lib.h"
36#include "gnunet_gns_service.h" 37#include "gnunet_gns_service.h"
@@ -49,6 +50,11 @@
49static struct GNUNET_NAMESTORE_Handle *namestore_handle; 50static struct GNUNET_NAMESTORE_Handle *namestore_handle;
50 51
51/** 52/**
53 * Our handle to the vpn service
54 */
55static struct GNUNET_VPN_Handle *vpn_handle;
56
57/**
52 * Resolver handle to the dht 58 * Resolver handle to the dht
53 */ 59 */
54static struct GNUNET_DHT_Handle *dht_handle; 60static struct GNUNET_DHT_Handle *dht_handle;
@@ -1166,11 +1172,202 @@ process_record_result_ns(void* cls,
1166 1172
1167 1173
1168/** 1174/**
1175 * VPN redirect result callback
1176 *
1177 * @param cls the resolver handle
1178 * @param af the requested address family
1179 * @param address in_addr(6) respectively
1180 */
1181static void
1182process_record_result_vpn (void* cls, int af, const void *address)
1183{
1184 struct ResolverHandle *rh = cls;
1185 struct RecordLookupHandle *rlh;
1186 struct GNUNET_NAMESTORE_RecordData rd;
1187
1188 rlh = (struct RecordLookupHandle *)rh->proc_cls;
1189
1190 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1191 "GNS_PHASE_REC_VPN-%d: Got answer from VPN to query!\n",
1192 rh->id);
1193 if (af == AF_INET)
1194 {
1195 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1196 "GNS_PHASE_REC-%d: Answer is IPv4!\n",
1197 rh->id);
1198 if (rlh->record_type != GNUNET_GNS_RECORD_TYPE_A)
1199 {
1200 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1201 "GNS_PHASE_REC-%d: Requested record is not IPv4!\n",
1202 rh->id);
1203 rh->proc (rh->proc_cls, rh, 0, NULL);
1204 return;
1205 }
1206 rd.record_type = GNUNET_GNS_RECORD_TYPE_A;
1207 rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
1208 rd.data = address;
1209 rd.data_size = sizeof (struct in_addr);
1210 rd.flags = 0;
1211 rh->proc (rh->proc_cls, rh, 1, &rd);
1212 return;
1213 }
1214 else if (af == AF_INET6)
1215 {
1216 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1217 "GNS_PHASE_REC-%d: Answer is IPv6!\n",
1218 rh->id);
1219 if (rlh->record_type != GNUNET_GNS_RECORD_AAAA)
1220 {
1221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1222 "GNS_PHASE_REC-%d: Requested record is not IPv6!\n",
1223 rh->id);
1224 rh->proc (rh->proc_cls, rh, 0, NULL);
1225 return;
1226 }
1227 rd.record_type = GNUNET_GNS_RECORD_AAAA;
1228 rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
1229 rd.data = address;
1230 rd.data_size = sizeof (struct in6_addr);
1231 rd.flags = 0;
1232 rh->proc (rh->proc_cls, rh, 1, &rd);
1233 return;
1234 }
1235
1236 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1237 "GNS_PHASE_REC-%d: Got garbage from VPN!\n",
1238 rh->id);
1239 rh->proc (rh->proc_cls, rh, 0, NULL);
1240}
1241
1242
1243/**
1244 * finish lookup
1245 *
1246 * @param rh resolver handle
1247 * @param rlh record lookup handle
1248 * @param rd_cound number of results
1249 * @param rd results
1250 */
1251static void
1252finish_lookup(struct ResolverHandle *rh,
1253 struct RecordLookupHandle* rlh,
1254 unsigned int rd_count,
1255 const struct GNUNET_NAMESTORE_RecordData *rd);
1256
1257/**
1258 * Process VPN lookup result for record
1259 *
1260 * @param cls the record lookup handle
1261 * @param rh resolver handle
1262 * @param rd_count number of results (1)
1263 * @param rd record data containing the result
1264 */
1265static void
1266handle_record_vpn (void* cls, struct ResolverHandle *rh,
1267 unsigned int rd_count,
1268 const struct GNUNET_NAMESTORE_RecordData *rd)
1269{
1270 struct RecordLookupHandle* rlh = (struct RecordLookupHandle*) cls;
1271
1272 if (rd_count == 0)
1273 {
1274 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1275 "GNS_PHASE_REC_VPN-%d: VPN returned no records. (status: %d)!\n",
1276 rh->id,
1277 rh->status);
1278 /* give up, cannot resolve */
1279 finish_lookup(rh, rlh, 0, NULL);
1280 free_resolver_handle(rh);
1281 return;
1282 }
1283
1284 /* results found yay */
1285 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1286 "GNS_PHASE_REC_VPN-%d: Record resolved from VPN!", rh->id);
1287
1288 finish_lookup(rh, rlh, rd_count, rd);
1289
1290 free_resolver_handle(rh);
1291}
1292
1293
1294/**
1295 * The final phase of resoution.
1296 * We found a VPN RR and want to request an IPv4/6 address
1297 *
1298 * @param rh the pending lookup handle
1299 * @param rd_count length of record data
1300 * @param rd record data containing VPN RR
1301 */
1302static void
1303resolve_record_vpn (struct ResolverHandle *rh,
1304 int rd_count,
1305 const struct GNUNET_NAMESTORE_RecordData *rd)
1306{
1307 int af;
1308 int proto;
1309 struct GNUNET_HashCode peer_id;
1310 struct GNUNET_CRYPTO_HashAsciiEncoded s_pid;
1311 struct GNUNET_HashCode serv_desc;
1312 struct GNUNET_CRYPTO_HashAsciiEncoded s_sd;
1313
1314 /* We cancel here as to not include the ns lookup in the timeout */
1315 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1316 {
1317 GNUNET_SCHEDULER_cancel(rh->timeout_task);
1318 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1319 }
1320 /* Start shortening */
1321 if ((rh->priv_key != NULL) && is_canonical (rh->name))
1322 {
1323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1324 "GNS_PHASE_REC_VPN-%llu: Trying to shorten authority chain\n",
1325 rh->id);
1326 start_shorten (rh->authority_chain_tail,
1327 rh->priv_key);
1328 }
1329
1330 /* Extracting VPN information FIXME rd parsing with NS API?*/
1331 if (4 != SSCANF ((char*)rd, "%d:%d:%s:%s", &af, &proto,
1332 (char*)&s_pid, (char*)&s_sd))
1333 {
1334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1335 "GNS_PHASE_REC_VPN-%llu: Error parsing VPN RR!\n",
1336 rh->id);
1337 rh->proc(rh->proc_cls, rh, 0, NULL);
1338 return;
1339 }
1340
1341 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_pid, &peer_id)) ||
1342 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_sd, &serv_desc)))
1343 {
1344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1345 "GNS_PHASE_REC_VPN-%llu: Error parsing VPN RR hashes!\n",
1346 rh->id);
1347 rh->proc(rh->proc_cls, rh, 0, NULL);
1348 return;
1349 }
1350
1351 rh->proc = &handle_record_vpn;
1352
1353 //FIXME timeout??
1354 rh->vpn_handle = GNUNET_VPN_redirect_to_peer (vpn_handle,
1355 af, proto,
1356 (struct GNUNET_PeerIdentity*)&peer_id,
1357 &serv_desc,
1358 GNUNET_NO, //nac
1359 GNUNET_TIME_UNIT_FOREVER_ABS, //FIXME
1360 &process_record_result_vpn,
1361 rh);
1362
1363}
1364
1365/**
1169 * The final phase of resolution. 1366 * The final phase of resolution.
1170 * rh->name is a name that is canonical and we do not have a delegation. 1367 * rh->name is a name that is canonical and we do not have a delegation.
1171 * Query namestore for this record 1368 * Query namestore for this record
1172 * 1369 *
1173 * @param rh the pending lookup 1370 * @param rh the pending lookup handle
1174 */ 1371 */
1175static void 1372static void
1176resolve_record_ns(struct ResolverHandle *rh) 1373resolve_record_ns(struct ResolverHandle *rh)
@@ -1665,6 +1862,8 @@ handle_record_dht(void* cls, struct ResolverHandle *rh,
1665} 1862}
1666 1863
1667 1864
1865
1866
1668/** 1867/**
1669 * Process namestore lookup result for record. 1868 * Process namestore lookup result for record.
1670 * 1869 *
@@ -1674,9 +1873,9 @@ handle_record_dht(void* cls, struct ResolverHandle *rh,
1674 * @param rd record data 1873 * @param rd record data
1675 */ 1874 */
1676static void 1875static void
1677handle_record_ns(void* cls, struct ResolverHandle *rh, 1876handle_record_ns (void* cls, struct ResolverHandle *rh,
1678 unsigned int rd_count, 1877 unsigned int rd_count,
1679 const struct GNUNET_NAMESTORE_RecordData *rd) 1878 const struct GNUNET_NAMESTORE_RecordData *rd)
1680{ 1879{
1681 struct RecordLookupHandle* rlh; 1880 struct RecordLookupHandle* rlh;
1682 rlh = (struct RecordLookupHandle*) cls; 1881 rlh = (struct RecordLookupHandle*) cls;
@@ -1956,9 +2155,25 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh,
1956 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2155 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1957 "GNS_PHASE_DELEGATE_NS-%llu: Resolved full name for delegation.\n", 2156 "GNS_PHASE_DELEGATE_NS-%llu: Resolved full name for delegation.\n",
1958 rh->id); 2157 rh->id);
1959 strcpy(rh->name, "+\0"); 2158
1960 rh->proc = &handle_record_ns; 2159 if (rh->status & RSL_DELEGATE_VPN)
1961 resolve_record_ns(rh); 2160 {
2161 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2162 "GNS_PHASE_DELEGATE_NS-%llu: VPN delegation starting.\n",
2163 rh->id);
2164 GNUNET_assert (NULL != rd);
2165 rh->proc = &handle_record_vpn;
2166 resolve_record_vpn (rh, rd_count, rd);
2167 }
2168 else
2169 {
2170 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2171 "GNS_PHASE_DELEGATE_NS-%llu: Resolving record +\n",
2172 rh->id);
2173 strcpy(rh->name, "+\0");
2174 rh->proc = &handle_record_ns;
2175 resolve_record_ns(rh);
2176 }
1962 return; 2177 return;
1963 } 2178 }
1964 2179
@@ -2118,6 +2333,18 @@ process_delegation_result_ns(void* cls,
2118 int i; 2333 int i;
2119 for (i=0; i<rd_count;i++) 2334 for (i=0; i<rd_count;i++)
2120 { 2335 {
2336 /**
2337 * Redirect via VPN
2338 */
2339 if (rd[i].record_type == GNUNET_GNS_RECORD_VPN)
2340 {
2341 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2342 "GNS_PHASE_DELEGATE_NS-%llu: VPNRR found.\n",
2343 rh->id);
2344 rh->status |= RSL_DELEGATE_VPN;
2345 rh->proc(rh->proc_cls, rh, rd_count, rd);
2346 return;
2347 }
2121 2348
2122 if (rd[i].record_type != GNUNET_GNS_RECORD_PKEY) 2349 if (rd[i].record_type != GNUNET_GNS_RECORD_PKEY)
2123 continue; 2350 continue;
@@ -2127,8 +2354,8 @@ process_delegation_result_ns(void* cls,
2127 { 2354 {
2128 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2355 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2129 "GNS_PHASE_DELEGATE_NS-%llu: PKEY for %s is pending user confirmation.\n", 2356 "GNS_PHASE_DELEGATE_NS-%llu: PKEY for %s is pending user confirmation.\n",
2130 name, 2357 rh->id,
2131 rh->id); 2358 name);
2132 continue; 2359 continue;
2133 } 2360 }
2134 2361
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h
index 1b54d3c2c..8387e1166 100644
--- a/src/gns/gnunet-service-gns_resolver.h
+++ b/src/gns/gnunet-service-gns_resolver.h
@@ -93,7 +93,8 @@ enum ResolutionStatus
93{ 93{
94 RSL_RECORD_EXISTS = 1, 94 RSL_RECORD_EXISTS = 1,
95 RSL_RECORD_EXPIRED = 2, 95 RSL_RECORD_EXPIRED = 2,
96 RSL_TIMED_OUT = 4 96 RSL_TIMED_OUT = 4,
97 RSL_DELEGATE_VPN = 8
97}; 98};
98 99
99/** 100/**
@@ -129,6 +130,9 @@ struct ResolverHandle
129 /* timeout set for this lookup task */ 130 /* timeout set for this lookup task */
130 struct GNUNET_TIME_Relative timeout; 131 struct GNUNET_TIME_Relative timeout;
131 132
133 /* a handle to a vpn request */
134 struct GNUNET_VPN_RedirectionRequest *vpn_handle;
135
132 /* timeout task for the lookup */ 136 /* timeout task for the lookup */
133 GNUNET_SCHEDULER_TaskIdentifier timeout_task; 137 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
134 138
diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h
index 5bebee633..827b6a482 100644
--- a/src/include/gnunet_gns_service.h
+++ b/src/include/gnunet_gns_service.h
@@ -80,7 +80,8 @@ enum GNUNET_GNS_RecordType
80 GNUNET_GNS_RECORD_PKEY = GNUNET_NAMESTORE_TYPE_PKEY, 80 GNUNET_GNS_RECORD_PKEY = GNUNET_NAMESTORE_TYPE_PKEY,
81 GNUNET_GNS_RECORD_PSEU = GNUNET_NAMESTORE_TYPE_PSEU, 81 GNUNET_GNS_RECORD_PSEU = GNUNET_NAMESTORE_TYPE_PSEU,
82 GNUNET_GNS_RECORD_ANY = GNUNET_NAMESTORE_TYPE_ANY, 82 GNUNET_GNS_RECORD_ANY = GNUNET_NAMESTORE_TYPE_ANY,
83 GNUNET_GNS_RECORD_LEHO = GNUNET_NAMESTORE_TYPE_LEHO 83 GNUNET_GNS_RECORD_LEHO = GNUNET_NAMESTORE_TYPE_LEHO,
84 GNUNET_GNS_RECORD_VPN
84}; 85};
85 86
86/** 87/**