commit 788a15d1c82a562e7080d3c523b30340938d8f1d
parent 41b1445ce9191b4f4a3a6355dad24d39945f3b69
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Sat, 20 Nov 2021 04:20:03 +0100
Simplified identity keys into basic strings to integrate into ui
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
7 files changed, 75 insertions(+), 6 deletions(-)
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h
@@ -324,7 +324,7 @@ GNUNET_CHAT_get_name (const struct GNUNET_CHAT_Handle *handle);
* @param[in] handle Chat handle
* @return Public key of the handles ego or NULL
*/
-const struct GNUNET_IDENTITY_PublicKey*
+const char*
GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle);
/**
@@ -409,7 +409,7 @@ GNUNET_CHAT_contact_get_name (const struct GNUNET_CHAT_Contact *contact);
* @param[in] contact Contact
* @return Public key of the contacts ego or NULL
*/
-const struct GNUNET_IDENTITY_PublicKey*
+const char*
GNUNET_CHAT_contact_get_key (const struct GNUNET_CHAT_Contact *contact);
/**
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
@@ -37,15 +37,40 @@ contact_create_from_member (struct GNUNET_CHAT_Handle *handle,
contact->member = member;
+ contact->public_key = NULL;
contact->user_pointer = NULL;
+ contact_update_key (contact);
return contact;
}
void
+contact_update_key (struct GNUNET_CHAT_Contact *contact)
+{
+ GNUNET_assert(contact);
+
+ if (contact->public_key)
+ GNUNET_free(contact->public_key);
+
+ contact->public_key = NULL;
+
+ if (!contact->member)
+ return;
+
+ const struct GNUNET_IDENTITY_PublicKey *pubkey;
+ pubkey = GNUNET_MESSENGER_contact_get_key(contact->member);
+
+ if (pubkey)
+ contact->public_key = GNUNET_IDENTITY_public_key_to_string(pubkey);
+}
+
+void
contact_destroy (struct GNUNET_CHAT_Contact* contact)
{
GNUNET_assert(contact);
+ if (contact->public_key)
+ GNUNET_free(contact->public_key);
+
GNUNET_free(contact);
}
diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h
@@ -40,6 +40,7 @@ struct GNUNET_CHAT_Contact
const struct GNUNET_MESSENGER_Contact *member;
+ char *public_key;
void *user_pointer;
};
@@ -48,6 +49,9 @@ contact_create_from_member (struct GNUNET_CHAT_Handle *handle,
const struct GNUNET_MESSENGER_Contact *member);
void
+contact_update_key (struct GNUNET_CHAT_Contact *contact);
+
+void
contact_destroy (struct GNUNET_CHAT_Contact* contact);
#endif /* GNUNET_CHAT_CONTACT_H_ */
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
@@ -84,12 +84,34 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
on_handle_message, handle
);
+ handle->public_key = NULL;
handle->user_pointer = NULL;
+ handle_update_key(handle);
return handle;
}
void
+handle_update_key (struct GNUNET_CHAT_Handle *handle)
+{
+ GNUNET_assert(handle);
+
+ if (handle->public_key)
+ GNUNET_free(handle->public_key);
+
+ handle->public_key = NULL;
+
+ if (!handle->messenger)
+ return;
+
+ const struct GNUNET_IDENTITY_PublicKey *pubkey;
+ pubkey = GNUNET_MESSENGER_get_key(handle->messenger);
+
+ if (pubkey)
+ handle->public_key = GNUNET_IDENTITY_public_key_to_string(pubkey);
+}
+
+void
handle_destroy (struct GNUNET_CHAT_Handle* handle)
{
GNUNET_assert((handle) &&
@@ -98,6 +120,9 @@ handle_destroy (struct GNUNET_CHAT_Handle* handle)
(handle->contexts) &&
(handle->files));
+ if (handle->public_key)
+ GNUNET_free(handle->public_key);
+
if (handle->messenger)
GNUNET_MESSENGER_disconnect(handle->messenger);
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
@@ -54,6 +54,7 @@ struct GNUNET_CHAT_Handle
struct GNUNET_FS_Handle *fs;
struct GNUNET_MESSENGER_Handle *messenger;
+ char *public_key;
void *user_pointer;
};
@@ -65,6 +66,9 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
void *msg_cls);
void
+handle_update_key (struct GNUNET_CHAT_Handle *handle);
+
+void
handle_destroy (struct GNUNET_CHAT_Handle* handle);
#endif /* GNUNET_CHAT_HANDLE_H_ */
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
@@ -397,6 +397,8 @@ on_handle_identity(void *cls,
(handle->groups) &&
(handle->contacts));
+ handle_update_key(handle);
+
if ((0 < GNUNET_CONTAINER_multihashmap_size(handle->contexts)) ||
(0 < GNUNET_CONTAINER_multihashmap_size(handle->groups)) ||
(0 < GNUNET_CONTAINER_multishortmap_size(handle->contacts)))
@@ -488,6 +490,15 @@ on_handle_message (void *cls,
switch (msg->header.kind)
{
+ case GNUNET_MESSENGER_KIND_KEY:
+ {
+ struct GNUNET_CHAT_Contact *contact = GNUNET_CONTAINER_multishortmap_get(
+ handle->contacts, &shorthash
+ );
+
+ contact_update_key(contact);
+ break;
+ }
case GNUNET_MESSENGER_KIND_INVITE:
{
struct GNUNET_CHAT_Invitation *invitation = invitation_create_from_message(
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -97,13 +97,13 @@ GNUNET_CHAT_get_name (const struct GNUNET_CHAT_Handle *handle)
}
-const struct GNUNET_IDENTITY_PublicKey*
+const char*
GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle)
{
if (!handle)
return NULL;
- return GNUNET_MESSENGER_get_key(handle->messenger);
+ return handle->public_key;
}
@@ -277,13 +277,13 @@ GNUNET_CHAT_contact_get_name (const struct GNUNET_CHAT_Contact *contact)
}
-const struct GNUNET_IDENTITY_PublicKey*
+const char*
GNUNET_CHAT_contact_get_key (const struct GNUNET_CHAT_Contact *contact)
{
if (!contact)
return NULL;
- return GNUNET_MESSENGER_contact_get_key(contact->member);
+ return contact->public_key;
}