aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-25 21:35:35 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-25 21:35:35 +0000
commita7cb864c5e86310bfc46c5d7eb683dde1078715a (patch)
treeccce67607efe4e6dd94718487df88548d642d6e9 /src
parentbb613dd9d32c66e3eb6d87f583d2be137d4137e6 (diff)
downloadgnunet-a7cb864c5e86310bfc46c5d7eb683dde1078715a.tar.gz
gnunet-a7cb864c5e86310bfc46c5d7eb683dde1078715a.zip
-add bg lookups for shorten
Diffstat (limited to 'src')
-rw-r--r--src/gns/gnunet-service-gns.c7
-rw-r--r--src/gns/gnunet-service-gns_resolver.c65
-rw-r--r--src/gns/gnunet-service-gns_resolver.h2
3 files changed, 73 insertions, 1 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 312827788..9947dc03f 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -493,7 +493,12 @@ static void handle_shorten(void *cls,
493 } 493 }
494 494
495 /* Start shortening */ 495 /* Start shortening */
496 gns_resolver_shorten_name(zone_hash, name, &send_shorten_response, csh); 496 if (GNUNET_YES == auto_import_pkey)
497 gns_resolver_shorten_name(zone_hash, name, zone_key,
498 &send_shorten_response, csh);
499 else
500 gns_resolver_shorten_name(zone_hash, name, NULL,
501 &send_shorten_response, csh);
497} 502}
498 503
499 504
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 4953f17db..556d39d2a 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -2137,6 +2137,26 @@ process_zone_to_name_shorten(void *cls,
2137 } 2137 }
2138} 2138}
2139 2139
2140/**
2141 * DHT resolution for delegation finished. Processing result.
2142 *
2143 * @param cls the closure
2144 * @param rh resolver handle
2145 * @param rd_count number of results (always 0)
2146 * @param rd record data (always NULL)
2147 */
2148static void
2149handle_delegation_dht_bg_shorten(void* cls, struct ResolverHandle *rh,
2150 unsigned int rd_count,
2151 const struct GNUNET_NAMESTORE_RecordData *rd)
2152{
2153
2154 /* We resolved full name for delegation. resolving record */
2155 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2156 "GNS_SHORTEN: Resolved up to %s for delegation via DHT in background.\n",
2157 rh->name);
2158 free_resolver_handle(rh);
2159}
2140 2160
2141/** 2161/**
2142 * Process result from namestore delegation lookup 2162 * Process result from namestore delegation lookup
@@ -2156,6 +2176,7 @@ handle_delegation_ns_shorten(void* cls,
2156 struct NameShortenHandle *nsh; 2176 struct NameShortenHandle *nsh;
2157 char result[MAX_DNS_NAME_LENGTH]; 2177 char result[MAX_DNS_NAME_LENGTH];
2158 size_t answer_len; 2178 size_t answer_len;
2179 struct ResolverHandle *rh_bg;
2159 2180
2160 nsh = (struct NameShortenHandle *)cls; 2181 nsh = (struct NameShortenHandle *)cls;
2161 2182
@@ -2193,12 +2214,46 @@ handle_delegation_ns_shorten(void* cls,
2193 return; 2214 return;
2194 } 2215 }
2195 2216
2217 /**
2218 * we have to this before zone to name for rh might
2219 * be freed by then
2220 */
2221 rh_bg = NULL;
2222 if (!is_canonical(rh->name))
2223 {
2224 rh_bg = GNUNET_malloc(sizeof(struct ResolverHandle));
2225 memcpy(rh_bg, rh, sizeof(struct ResolverHandle));
2226 }
2227
2196 /* backtrack authorities for names */ 2228 /* backtrack authorities for names */
2197 GNUNET_NAMESTORE_zone_to_name (namestore_handle, 2229 GNUNET_NAMESTORE_zone_to_name (namestore_handle,
2198 &rh->authority_chain_tail->zone, //ours 2230 &rh->authority_chain_tail->zone, //ours
2199 &rh->authority_chain_head->zone, 2231 &rh->authority_chain_head->zone,
2200 &process_zone_to_name_shorten, 2232 &process_zone_to_name_shorten,
2201 rh); 2233 rh);
2234
2235 if (rh_bg == NULL)
2236 {
2237 return;
2238 }
2239
2240 /**
2241 * If authority resolution is incomplete we can do a background lookup
2242 * of the full name so that next time we can (likely) fully or at least
2243 * further shorten the name
2244 */
2245 rh_bg->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain));
2246 rh_bg->authority_chain_tail = rh_bg->authority_chain_head;
2247 rh_bg->authority_chain_head->zone = rh_bg->authority;
2248
2249 rh_bg->proc = &handle_delegation_dht_bg_shorten;
2250 rh_bg->proc_cls = NULL;
2251
2252 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2253 "GNS_SHORTEN: Starting background lookup for %s\n",
2254 rh_bg->name);
2255
2256 resolve_delegation_dht(rh_bg);
2202 2257
2203} 2258}
2204 2259
@@ -2232,6 +2287,13 @@ process_zone_to_name_zkey(void *cls,
2232 /* zkey not in our zone */ 2287 /* zkey not in our zone */
2233 if (name == NULL) 2288 if (name == NULL)
2234 { 2289 {
2290 /**
2291 * In this case we have not given this PKEY a name (yet)
2292 * It is either just not in our zone or not even cached
2293 * Since we do not know at this point we will not try to shorten
2294 * because PKEY import will happen if the user follows the zkey
2295 * link.
2296 */
2235 GNUNET_CRYPTO_short_hash_to_enc ((struct GNUNET_CRYPTO_ShortHashCode*)rd, 2297 GNUNET_CRYPTO_short_hash_to_enc ((struct GNUNET_CRYPTO_ShortHashCode*)rd,
2236 &enc); 2298 &enc);
2237 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2299 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -2273,12 +2335,14 @@ process_zone_to_name_zkey(void *cls,
2273 * 2335 *
2274 * @param zone the zone to use 2336 * @param zone the zone to use
2275 * @param name the name to shorten 2337 * @param name the name to shorten
2338 * @param key optional private key for background lookups and PSEU import
2276 * @param proc the processor to call with result 2339 * @param proc the processor to call with result
2277 * @param proc_cls closure to pass to proc 2340 * @param proc_cls closure to pass to proc
2278 */ 2341 */
2279void 2342void
2280gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone, 2343gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
2281 const char* name, 2344 const char* name,
2345 struct GNUNET_CRYPTO_RsaPrivateKey *key,
2282 ShortenResultProcessor proc, 2346 ShortenResultProcessor proc,
2283 void* proc_cls) 2347 void* proc_cls)
2284{ 2348{
@@ -2309,6 +2373,7 @@ gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
2309 2373
2310 rh = GNUNET_malloc(sizeof (struct ResolverHandle)); 2374 rh = GNUNET_malloc(sizeof (struct ResolverHandle));
2311 rh->authority = zone; 2375 rh->authority = zone;
2376 rh->priv_key = key;
2312 rh->proc = &handle_delegation_ns_shorten; 2377 rh->proc = &handle_delegation_ns_shorten;
2313 rh->proc_cls = nsh; 2378 rh->proc_cls = nsh;
2314 2379
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h
index ad7ff6223..85c21e324 100644
--- a/src/gns/gnunet-service-gns_resolver.h
+++ b/src/gns/gnunet-service-gns_resolver.h
@@ -296,12 +296,14 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
296 * 296 *
297 * @param zone the zone to perform the operation in 297 * @param zone the zone to perform the operation in
298 * @param name name to shorten 298 * @param name name to shorten
299 * @param key optional private key for background lookups and PSEU import
299 * @param proc the processor to call on shorten result 300 * @param proc the processor to call on shorten result
300 * @param proc_cls the closure to pass to proc 301 * @param proc_cls the closure to pass to proc
301 */ 302 */
302void 303void
303gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone, 304gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
304 const char* name, 305 const char* name,
306 struct GNUNET_CRYPTO_RsaPrivateKey *key,
305 ShortenResultProcessor proc, 307 ShortenResultProcessor proc,
306 void* proc_cls); 308 void* proc_cls);
307 309