diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-08-24 16:08:21 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-08-24 16:08:21 +0000 |
commit | 6811cb762f1edb84fc312ad955e2fb05c047c24d (patch) | |
tree | 7c80651fa403c7fe56e8ae6bf9673d1ccfe6bd84 /src/gns/gnunet-gns.c | |
parent | 0baf38e846d5a4cd5b5b4c2ec900762fceb87712 (diff) | |
download | gnunet-6811cb762f1edb84fc312ad955e2fb05c047c24d.tar.gz gnunet-6811cb762f1edb84fc312ad955e2fb05c047c24d.zip |
-use identity service also for shorten zone lookup
Diffstat (limited to 'src/gns/gnunet-gns.c')
-rw-r--r-- | src/gns/gnunet-gns.c | 154 |
1 files changed, 87 insertions, 67 deletions
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index 881b88810..28e06e844 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c | |||
@@ -75,9 +75,9 @@ static int rtype; | |||
75 | static struct GNUNET_GNS_LookupRequest *lookup_request; | 75 | static struct GNUNET_GNS_LookupRequest *lookup_request; |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Handle to the identity service. | 78 | * Lookup an ego with the identity service. |
79 | */ | 79 | */ |
80 | static struct GNUNET_IDENTITY_Handle *identity; | 80 | static struct GNUNET_IDENTITY_EgoLookup *el; |
81 | 81 | ||
82 | 82 | ||
83 | /** | 83 | /** |
@@ -90,10 +90,10 @@ static void | |||
90 | do_shutdown (void *cls, | 90 | do_shutdown (void *cls, |
91 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 91 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
92 | { | 92 | { |
93 | if (NULL != identity) | 93 | if (NULL != el) |
94 | { | 94 | { |
95 | GNUNET_IDENTITY_disconnect (identity); | 95 | GNUNET_IDENTITY_ego_lookup_cancel (el); |
96 | identity = NULL; | 96 | el = NULL; |
97 | } | 97 | } |
98 | if (NULL != lookup_request) | 98 | if (NULL != lookup_request) |
99 | { | 99 | { |
@@ -154,29 +154,15 @@ process_lookup_result (void *cls, uint32_t rd_count, | |||
154 | 154 | ||
155 | /** | 155 | /** |
156 | * Perform the actual resolution, starting with the zone | 156 | * Perform the actual resolution, starting with the zone |
157 | * identified by the given public key. | 157 | * identified by the given public key and the shorten zone. |
158 | * | 158 | * |
159 | * @param pkey public key to use for the zone | 159 | * @param pkey public key to use for the zone, can be NULL |
160 | * @param shorten_key private key used for shortening, can be NULL | ||
160 | */ | 161 | */ |
161 | static void | 162 | static void |
162 | lookup_with_public_key (const struct GNUNET_CRYPTO_EccPublicKey *pkey) | 163 | lookup_with_keys (const struct GNUNET_CRYPTO_EccPublicKey *pkey, |
164 | const struct GNUNET_CRYPTO_EccPrivateKey *shorten_key) | ||
163 | { | 165 | { |
164 | char *keyfile; | ||
165 | struct GNUNET_CRYPTO_EccPrivateKey *shorten_key; | ||
166 | |||
167 | if (GNUNET_OK != | ||
168 | GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | ||
169 | "SHORTEN_ZONEKEY", &keyfile)) | ||
170 | { | ||
171 | shorten_key = NULL; | ||
172 | } | ||
173 | else | ||
174 | { | ||
175 | // FIXME: use identity service! | ||
176 | shorten_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile); | ||
177 | GNUNET_free (keyfile); | ||
178 | } | ||
179 | |||
180 | if (NULL != lookup_type) | 166 | if (NULL != lookup_type) |
181 | rtype = GNUNET_NAMESTORE_typename_to_number (lookup_type); | 167 | rtype = GNUNET_NAMESTORE_typename_to_number (lookup_type); |
182 | else | 168 | else |
@@ -200,68 +186,101 @@ lookup_with_public_key (const struct GNUNET_CRYPTO_EccPublicKey *pkey) | |||
200 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 186 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
201 | return; | 187 | return; |
202 | } | 188 | } |
203 | GNUNET_free_non_null (shorten_key); | ||
204 | } | 189 | } |
205 | 190 | ||
206 | 191 | ||
207 | /** | 192 | /** |
208 | * Method called to inform about the egos of this peer. | 193 | * Method called to with the ego we are to use for the lookup. |
209 | * | 194 | * |
210 | * When used with #GNUNET_IDENTITY_connect, this function is | 195 | * @param cls closure with the `struct GNUNET_CRYPTO_EccPublicKey` |
211 | * initially called for all egos and then again whenever a | 196 | * @param ego ego handle, NULL if not found |
212 | * ego's name changes or if it is deleted. At the end of | 197 | */ |
213 | * the initial pass over all egos, the function is once called | 198 | static void |
214 | * with 'NULL' for @a ego. That does NOT mean that the callback won't | 199 | shorten_cb (void *cls, |
215 | * be invoked in the future or that there was an error. | 200 | const struct GNUNET_IDENTITY_Ego *ego) |
201 | { | ||
202 | struct GNUNET_CRYPTO_EccPublicKey *pkey = cls; | ||
203 | const struct GNUNET_CRYPTO_EccPrivateKey *shorten_key; | ||
204 | |||
205 | el = NULL; | ||
206 | if (NULL == ego) | ||
207 | { | ||
208 | fprintf (stderr, | ||
209 | _("Shorten zone not found (looking up without shortening)\n")); | ||
210 | shorten_key = NULL; | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | shorten_key = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
215 | } | ||
216 | lookup_with_keys (pkey, shorten_key); | ||
217 | GNUNET_free_non_null (pkey); | ||
218 | } | ||
219 | |||
220 | |||
221 | /** | ||
222 | * Perform the actual resolution, starting with the zone | ||
223 | * identified by the given public key. | ||
216 | * | 224 | * |
217 | * If the @a name matches the `zone_ego_name`, we found the zone | 225 | * @param pkey public key to use for the zone |
218 | * for our computation and will begin resolving against that zone. | 226 | */ |
219 | * If we have iterated over all egos and not found the name, we | 227 | static void |
220 | * terminate the program with an error message. | 228 | lookup_with_public_key (const struct GNUNET_CRYPTO_EccPublicKey *pkey) |
229 | { | ||
230 | struct GNUNET_CRYPTO_EccPublicKey *pkeym; | ||
231 | char *szone; | ||
232 | |||
233 | if (GNUNET_OK != | ||
234 | GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | ||
235 | "SHORTEN_ZONE", &szone)) | ||
236 | { | ||
237 | lookup_with_keys (pkey, NULL); | ||
238 | return; | ||
239 | } | ||
240 | if (NULL == pkey) | ||
241 | { | ||
242 | pkeym = NULL; | ||
243 | } | ||
244 | else | ||
245 | { | ||
246 | pkeym = GNUNET_new (struct GNUNET_CRYPTO_EccPublicKey); | ||
247 | *pkeym = *pkey; | ||
248 | } | ||
249 | el = GNUNET_IDENTITY_ego_lookup (cfg, | ||
250 | szone, | ||
251 | &shorten_cb, | ||
252 | pkeym); | ||
253 | GNUNET_free (szone); | ||
254 | } | ||
255 | |||
256 | |||
257 | /** | ||
258 | * Method called to with the ego we are to use for the lookup. | ||
221 | * | 259 | * |
222 | * @param cls closure (NULL, unused) | 260 | * @param cls closure (NULL, unused) |
223 | * @param ego ego handle | 261 | * @param ego ego handle, NULL if not found |
224 | * @param ego_ctx context for application to store data for this ego | ||
225 | * (during the lifetime of this process, initially NULL) | ||
226 | * @param name name assigned by the user for this ego, | ||
227 | * NULL if the user just deleted the ego and it | ||
228 | * must thus no longer be used | ||
229 | */ | 262 | */ |
230 | static void | 263 | static void |
231 | identity_cb (void *cls, | 264 | identity_cb (void *cls, |
232 | struct GNUNET_IDENTITY_Ego *ego, | 265 | const struct GNUNET_IDENTITY_Ego *ego) |
233 | void **ctx, | ||
234 | const char *name) | ||
235 | { | 266 | { |
236 | struct GNUNET_CRYPTO_EccPublicKey pkey; | 267 | struct GNUNET_CRYPTO_EccPublicKey pkey; |
237 | 268 | ||
238 | if ( (NULL != zone_ego_name) && | 269 | el = NULL; |
239 | (NULL != name) && | 270 | if (NULL == ego) |
240 | (0 == strcmp (name, | ||
241 | zone_ego_name)) ) | ||
242 | { | ||
243 | GNUNET_IDENTITY_ego_get_public_key (ego, &pkey); | ||
244 | lookup_with_public_key (&pkey); | ||
245 | GNUNET_free (zone_ego_name); | ||
246 | zone_ego_name = NULL; | ||
247 | GNUNET_IDENTITY_disconnect (identity); | ||
248 | identity = NULL; | ||
249 | return; | ||
250 | } | ||
251 | if ( (NULL == ego) && | ||
252 | (NULL != identity) && | ||
253 | (NULL != zone_ego_name) ) | ||
254 | { | 271 | { |
255 | fprintf (stderr, | 272 | fprintf (stderr, |
256 | _("Ego `%s' not found\n"), | 273 | _("Ego `%s' not found\n"), |
257 | zone_ego_name); | 274 | zone_ego_name); |
258 | GNUNET_free (zone_ego_name); | 275 | GNUNET_free (zone_ego_name); |
259 | zone_ego_name = NULL; | 276 | zone_ego_name = NULL; |
260 | GNUNET_IDENTITY_disconnect (identity); | ||
261 | identity = NULL; | ||
262 | GNUNET_SCHEDULER_shutdown (); | 277 | GNUNET_SCHEDULER_shutdown (); |
263 | return; | 278 | return; |
264 | } | 279 | } |
280 | GNUNET_IDENTITY_ego_get_public_key (ego, &pkey); | ||
281 | lookup_with_public_key (&pkey); | ||
282 | GNUNET_free (zone_ego_name); | ||
283 | zone_ego_name = NULL; | ||
265 | } | 284 | } |
266 | 285 | ||
267 | 286 | ||
@@ -307,9 +326,10 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
307 | } | 326 | } |
308 | if (NULL != zone_ego_name) | 327 | if (NULL != zone_ego_name) |
309 | { | 328 | { |
310 | identity = GNUNET_IDENTITY_connect (cfg, | 329 | el = GNUNET_IDENTITY_ego_lookup (cfg, |
311 | &identity_cb, | 330 | zone_ego_name, |
312 | NULL); | 331 | &identity_cb, |
332 | NULL); | ||
313 | return; | 333 | return; |
314 | } | 334 | } |
315 | if ( (NULL != lookup_name) && | 335 | if ( (NULL != lookup_name) && |