diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-06-15 23:46:00 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-06-15 23:46:00 +0200 |
commit | a99752d30c73cd5040c9da3c05da3bbc2dc1b67e (patch) | |
tree | 4319210d4664aa3354404e67911ebe771b1e43f3 /src/gns/gns_tld_api.c | |
parent | b3ddc93861a6a171eee7c855f83c7a1314f6eaf9 (diff) | |
download | gnunet-a99752d30c73cd5040c9da3c05da3bbc2dc1b67e.tar.gz gnunet-a99752d30c73cd5040c9da3c05da3bbc2dc1b67e.zip |
fix gnunet-gns performance issue for many egos
Diffstat (limited to 'src/gns/gns_tld_api.c')
-rw-r--r-- | src/gns/gns_tld_api.c | 88 |
1 files changed, 28 insertions, 60 deletions
diff --git a/src/gns/gns_tld_api.c b/src/gns/gns_tld_api.c index fa4c9c057..f36b31acf 100644 --- a/src/gns/gns_tld_api.c +++ b/src/gns/gns_tld_api.c | |||
@@ -72,7 +72,7 @@ struct GNUNET_GNS_LookupWithTldRequest | |||
72 | /** | 72 | /** |
73 | * Lookup an ego with the identity service. | 73 | * Lookup an ego with the identity service. |
74 | */ | 74 | */ |
75 | struct GNUNET_IDENTITY_Handle *id_co; | 75 | struct GNUNET_IDENTITY_EgoSuffixLookup *id_co; |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Name of the longest matching ego found so far. | 78 | * Name of the longest matching ego found so far. |
@@ -191,68 +191,37 @@ lookup_with_public_key (struct GNUNET_GNS_LookupWithTldRequest *ltr, | |||
191 | */ | 191 | */ |
192 | static void | 192 | static void |
193 | identity_zone_cb (void *cls, | 193 | identity_zone_cb (void *cls, |
194 | struct GNUNET_IDENTITY_Ego *ego, | 194 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, |
195 | void **ctx, | 195 | const char *ego_name) |
196 | const char *name) | ||
197 | { | 196 | { |
198 | struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; | 197 | struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; |
199 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 198 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
200 | 199 | ||
201 | if (NULL == ego) | 200 | ltr->id_co = NULL; |
201 | if (NULL == priv) | ||
202 | { | 202 | { |
203 | if (NULL != ltr->longest_match) | 203 | /* no matching ego found */ |
204 | { | 204 | ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_NO, 0, NULL); |
205 | /* Final case: TLD matches one of our egos */ | ||
206 | // FIXME: eat all of the match (not just TLD!) | ||
207 | if (0 == strcmp (ltr->name, ltr->longest_match)) | ||
208 | { | ||
209 | /* name matches ego name perfectly, only "@" remains */ | ||
210 | strcpy (ltr->name, GNUNET_GNS_EMPTY_LABEL_AT); | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | GNUNET_assert (strlen (ltr->longest_match) < strlen (ltr->name)); | ||
215 | ltr->name[strlen (ltr->name) - strlen (ltr->longest_match) - 1] = '\0'; | ||
216 | } | ||
217 | |||
218 | /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */ | ||
219 | GNUNET_free (ltr->longest_match); | ||
220 | ltr->longest_match = NULL; | ||
221 | if (NULL == strchr (ltr->name, (unsigned char) '.')) | ||
222 | ltr->options = GNUNET_GNS_LO_NO_DHT; | ||
223 | else | ||
224 | ltr->options = GNUNET_GNS_LO_LOCAL_MASTER; | ||
225 | |||
226 | GNUNET_IDENTITY_ego_get_public_key (ltr->longest_match_ego, &pkey); | ||
227 | GNUNET_IDENTITY_disconnect (ltr->id_co); | ||
228 | ltr->id_co = NULL; | ||
229 | lookup_with_public_key (ltr, &pkey); | ||
230 | } | ||
231 | else | ||
232 | { | ||
233 | /* no matching ego found */ | ||
234 | GNUNET_IDENTITY_disconnect (ltr->id_co); | ||
235 | ltr->id_co = NULL; | ||
236 | ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_NO, 0, NULL); | ||
237 | GNUNET_GNS_lookup_with_tld_cancel (ltr); | ||
238 | } | ||
239 | return; | 205 | return; |
240 | } | 206 | } |
241 | else if (NULL != name) | 207 | /* Final case: TLD matches one of our egos */ |
208 | if (0 == strcmp (ltr->name, ego_name)) | ||
242 | { | 209 | { |
243 | if ((strlen (name) <= strlen (ltr->name)) && | 210 | /* name matches ego name perfectly, only "@" remains */ |
244 | (0 == strcmp (name, <r->name[strlen (ltr->name) - strlen (name)])) && | 211 | strcpy (ltr->name, GNUNET_GNS_EMPTY_LABEL_AT); |
245 | ((strlen (name) == strlen (ltr->name)) || | ||
246 | ('.' == ltr->name[strlen (ltr->name) - strlen (name) - 1])) && | ||
247 | ((NULL == ltr->longest_match) || | ||
248 | (strlen (name) > strlen (ltr->longest_match)))) | ||
249 | { | ||
250 | /* found better match, update! */ | ||
251 | GNUNET_free_non_null (ltr->longest_match); | ||
252 | ltr->longest_match = GNUNET_strdup (name); | ||
253 | ltr->longest_match_ego = ego; | ||
254 | } | ||
255 | } | 212 | } |
213 | else | ||
214 | { | ||
215 | GNUNET_assert (strlen (ego_name) < strlen (ltr->name)); | ||
216 | ltr->name[strlen (ltr->name) - strlen (ego_name) - 1] = '\0'; | ||
217 | } | ||
218 | /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */ | ||
219 | if (NULL == strchr (ltr->name, (unsigned char) '.')) | ||
220 | ltr->options = GNUNET_GNS_LO_NO_DHT; | ||
221 | else | ||
222 | ltr->options = GNUNET_GNS_LO_LOCAL_MASTER; | ||
223 | GNUNET_CRYPTO_ecdsa_key_get_public (priv, &pkey); | ||
224 | lookup_with_public_key (ltr, &pkey); | ||
256 | } | 225 | } |
257 | 226 | ||
258 | 227 | ||
@@ -336,12 +305,11 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, | |||
336 | } | 305 | } |
337 | GNUNET_free (dot_tld); | 306 | GNUNET_free (dot_tld); |
338 | } | 307 | } |
339 | /* FIXME: this call is still shitty slow to do the longest | ||
340 | suffix if we have thousands of egos. We should modify | ||
341 | the IDENTITY API to do the longest suffix matching | ||
342 | inside of the identity service and not do an O(n) IPC! */ | ||
343 | ltr->id_co = | 308 | ltr->id_co = |
344 | GNUNET_IDENTITY_connect (ltr->gns_handle->cfg, &identity_zone_cb, ltr); | 309 | GNUNET_IDENTITY_ego_lookup_by_suffix (ltr->gns_handle->cfg, |
310 | ltr->name, | ||
311 | &identity_zone_cb, | ||
312 | ltr); | ||
345 | if (NULL == ltr->id_co) | 313 | if (NULL == ltr->id_co) |
346 | { | 314 | { |
347 | GNUNET_free (ltr->name); | 315 | GNUNET_free (ltr->name); |
@@ -365,7 +333,7 @@ GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr) | |||
365 | 333 | ||
366 | if (NULL != ltr->id_co) | 334 | if (NULL != ltr->id_co) |
367 | { | 335 | { |
368 | GNUNET_IDENTITY_disconnect (ltr->id_co); | 336 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (ltr->id_co); |
369 | ltr->id_co = NULL; | 337 | ltr->id_co = NULL; |
370 | } | 338 | } |
371 | if (NULL != ltr->lr) | 339 | if (NULL != ltr->lr) |