From a99752d30c73cd5040c9da3c05da3bbc2dc1b67e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 15 Jun 2019 23:46:00 +0200 Subject: fix gnunet-gns performance issue for many egos --- src/identity/Makefile.am | 1 + src/identity/gnunet-service-identity.c | 71 ++++++++++++++++++++++++++++++++++ src/identity/identity.h | 3 +- 3 files changed, 74 insertions(+), 1 deletion(-) (limited to 'src/identity') diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am index 6e587dc86..476d981bb 100644 --- a/src/identity/Makefile.am +++ b/src/identity/Makefile.am @@ -43,6 +43,7 @@ libgnunet_plugin_rest_identity_la_LDFLAGS = \ libgnunetidentity_la_SOURCES = \ identity_api.c \ identity_api_lookup.c \ + identity_api_suffix_lookup.c \ identity.h libgnunetidentity_la_LIBADD = \ $(top_builddir)/src/util/libgnunetutil.la \ diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index a675a01f0..3e92a04cd 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c @@ -377,6 +377,73 @@ handle_lookup_message (void *cls, } +/** + * Handler for LOOKUP message from client, sends information + * about ONE identity to the client immediately. + * + * @param cls unused + * @param message the message received + * @return #GNUNET_SYSERR if message was ill-formed + */ +static int +check_lookup_by_suffix_message (void *cls, + const struct LookupMessage *message) +{ + GNUNET_MQ_check_zero_termination (message); + return GNUNET_OK; +} + + +/** + * Handler for LOOKUP_BY_SUFFIX message from client, sends information + * about ONE identity to the client immediately. + * + * @param cls a `struct GNUNET_SERVICE_Client *` + * @param message the message received + */ +static void +handle_lookup_by_suffix_message (void *cls, + const struct LookupMessage *message) +{ + struct GNUNET_SERVICE_Client *client = cls; + const char *name; + struct GNUNET_MQ_Envelope *env; + struct Ego *lprefix; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received LOOKUP_BY_SUFFIX message from client\n"); + name = (const char *) &message[1]; + lprefix = NULL; + for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next) + { + + if ((strlen (ego->identifier) <= strlen (name)) && + (0 == strcmp (ego->identifier, + &name[strlen (name) - strlen (ego->identifier)])) && + ((strlen (name) == strlen (ego->identifier)) || + ('.' == name[strlen (name) - + strlen (ego->identifier) - 1])) && + ((NULL == lprefix) || + (strlen (ego->identifier) > strlen (lprefix->identifier)))) + { + /* found better match, update! */ + lprefix = ego; + } + } + if (NULL != lprefix) + { + env = create_update_message (lprefix); + GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); + GNUNET_SERVICE_client_continue (client); + return; + } + send_result_code (client, + 0, + "ego not found"); + GNUNET_SERVICE_client_continue (client); +} + + /** * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT message * @@ -1118,6 +1185,10 @@ GNUNET_SERVICE_MAIN GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP, struct LookupMessage, NULL), + GNUNET_MQ_hd_var_size (lookup_by_suffix_message, + GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, + struct LookupMessage, + NULL), GNUNET_MQ_hd_var_size (get_default_message, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, struct GetDefaultMessage, diff --git a/src/identity/identity.h b/src/identity/identity.h index 96550bdf2..6ef16e39d 100644 --- a/src/identity/identity.h +++ b/src/identity/identity.h @@ -62,7 +62,8 @@ struct ResultCodeMessage struct LookupMessage { /** - * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP + * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP or + * #GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX */ struct GNUNET_MessageHeader header; -- cgit v1.2.3