summaryrefslogtreecommitdiff
path: root/src/identity
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-06-15 23:46:00 +0200
committerChristian Grothoff <christian@grothoff.org>2019-06-15 23:46:00 +0200
commita99752d30c73cd5040c9da3c05da3bbc2dc1b67e (patch)
tree4319210d4664aa3354404e67911ebe771b1e43f3 /src/identity
parentb3ddc93861a6a171eee7c855f83c7a1314f6eaf9 (diff)
fix gnunet-gns performance issue for many egos
Diffstat (limited to 'src/identity')
-rw-r--r--src/identity/Makefile.am1
-rw-r--r--src/identity/gnunet-service-identity.c71
-rw-r--r--src/identity/identity.h3
3 files changed, 74 insertions, 1 deletions
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
@@ -378,6 +378,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
*
* @param cls client sending the 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;